[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

make a simple rock paper scissors game or the bird will stab you

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 35
Thread images: 4

File: 1467386629306.jpg (29KB, 412x430px) Image search: [Google]
1467386629306.jpg
29KB, 412x430px
make a simple rock paper scissors game or the bird will stab you
>>
>download rock paper scissor library
This is the only correct answer
>>
Give us a reference implementation or I'll stab your homework.
>>
>>56249189
Here you are. There's not much time left before the bird loses its temper!
public class Rps {
public final static int ROCK = 0;
public final static int PAPER = 1;
public final static int SCISSORS = 2;

public final static int VICTORY = 1;
public final static int TIE = 0;
public final static int LOSS = -1;

public static void main() {
Random random = new Random();
Scanner scanner = new Scanner(System.in);
String input = "";


while (true) {
System.out.println("Type 0 for rock, 1 for paper, 2 for scissors, 3 to exit.");
int playerChoice = scanner.nextInt();
int computerChoice = random.nextInt(3);
if (playerChoice >= ROCK && playerChoice <= SCISSORS) {
int result = match(playerChoice, computerChoice);
switch (result) {
case VICTORY:
System.out.println("You've won!");
break;
case TIE:
System.out.println("You've tied!");
break;
case LOSS:
System.out.println("You've lost!");
break;
}
}
if (playerChoice == 4) {
System.out.println("Exiting...");
break;
} else {
System.out.println("invalid input");

}
}

}

private int match(int playerSelection, int computerSelection) {
if (playerSelection == computerSelection) {
return TIE;
} else if ((playerSelection == ROCK && computerSelection == PAPER) || (playerSelection == SCISSORS && computerSelection == PAPER) || (playerSelection == PAPER && computerSelection == ROCK)) {
return VICTORY;
} else {
return LOSS;
}
}
}
>>
We have this thread every week. Do your own homework, Pajeet Poinlo
>>
>>56249424
The bird senses that you aren't up to the challenge!
>>
>>56249137
import random
plays = {'rock': 'scissors', 'paper': 'rock', 'scissors': 'paper'}
while True:
choice1 = ''
while choice1 not in plays:
choice1 = raw_input('Choose rock/paper/scissors: ')
choice2 = random.choice(plays.keys())
print 'You choose %s, computer chooses %s' % (choice1, choice2)
if choice1 == choice2:
print 'It\'s a tie!'
elif plays[choice1] == choice2:
print 'You win!'
else:
print 'Computer wins!'
if raw_input('Play again? (y/N)').lower() == 'y':
break
>>
you = input()
opp = input()
print('win' if {'rock': 'scissors', 'scissors': 'paper', 'paper': 'rock'}[you] == opp else
'draw' if you == opp else 'lose')
>>
>>56249341
>rock beating paper
>>
>>56249137
local rps = {1 = "rock", 2 = "paper", 3 = "scissors"}
local getChoice = math.random(1, 3)
print(rps[getChoice])
>>
>>56249531
int main(int argc, char *argv[])
{
char you = argv[1][0];
char opp = argv[2][0];
puts(you == opp ? "draw" :
((char[]){['r'] = 's', ['s'] = 'p', ['p'] = 'r'})[you] == opp ? "win" : "lose");
return 0;
}
>>
File: IMG_20160804_193620.jpg (231KB, 1413x2603px) Image search: [Google]
IMG_20160804_193620.jpg
231KB, 1413x2603px
Checkmate atheists
>>
>>56249137
lmao I wrote a 321 line program in python to do this ages ago

I'm a little less retarded now

It did at least save scores to a file but still awful
>>
>>56249137


function rockPaperScissors(choice) {
var outcome = ~~(Math.random()*3);
switch(outcome) {
case 0:
console.log('You win!');
break;
case 1:
console.log('You lose!');
break;
case 2:
console.log('Tie!');
break;
}
}

>>
>>56249137
Doesn't seen so menacing to me tbqh senpai...
>>
>>56251355
Love it. The quintessential example of a black box program and a shitty set of requirements (rock, paper, scissors) to implement.
>>
>>56249137
do it I no longer fear death or dying
>>
>>56251355
I thought of a more compact way:


function rockPaperScissors(choice) {
const outcomes = ['You win!', 'You lose!', 'Tie'];
console.log(outcomes[~~(Math.random() * outcomes.length)]);
}

>>
10 RANDOMIZE TIMER
20 PRINT "PLEASE ENTER (R)OCK, (P)APER, or (S)CISSORS"
30 INPUT C$
40 LET C$ = LEFT$(C$, 1)
50 LET P = 0
60 IF C$ = "R" OR C$ = "r" THEN LET P = 1
70 IF C$ = "P" OR C$ = "p" THEN LET P = 2
80 IF C$ = "S" OR C$ = "s" THEN LET P = 3
90 IF P = 0 THEN GOTO 20
100 A = INT(RND * 3 + 1)
110 ON A GOTO 120, 140, 160
120 PRINT "COMPUTER CHOOSES ROCK"
130 ON P GOTO 200, 180, 220
140 PRINT "COMPUTER CHOOSES PAPER"
150 ON P GOTO 220, 200, 180
160 PRINT "COMPUTER CHOOSES SCISSORS"
170 ON P GOTO 180, 220, 200
180 PRINT "YOU WIN!"
190 GOTO 230
200 PRINT "TIE!"
210 GOTO 230
220 PRINT "COMPUTER WINS!"
230 INPUT "WOULD YOU LIKE TO PLAY AGAIN?", C$
240 LET C$ = LEFT$(C$, 1)
250 IF C$ = "Y" OR C$ = "y" THEN GOTO 20
260 END
>>
Due to probability, you could just program a random outcome anyway between lose, tie, and win. The user wouldn't notice the difference anyway.
>>
>>56251917
I wonder if a compiler would optimize the game out.
>>
>>56251260
Fuck man how do you even eat that many lines?
>>
>>56251938
Not if you actually wrote the full game, compilers aren't smart enough to look at the "big picture" like that (if they were, we'd be using declarative rather than imperative languages much more frequently). Most optimizations just eliminate code that will never be reached, such as in the body of a
 while(false) { ... }
statement, or simplifying expressions like
if (x > 0) x = 0;

to
x = 0;
>>
RPS <- function(x) {
choices <- c("Rock","Paper","Scissors")
if (identical(choices %in% x, integer(0)){
stop("You fucked up")
}
playerChoice <- which(choices %in% x)

computerChoice <- floor(runif(1,min=1,max=4))
if (computerChoice == playerChoice) {
print("Tie")
} else if ( (playerChoice + 1) %% 3 == computerChoice) {
print("Lose")
} else {
print("Win")
}
}
>>
>>56251917
Someone already did that in the thread above you.
>>
>>56251917
that's boring though
>>
technically 1 line

#include <stdlib.h>
#include <time.h>
#include <stdio.h>
int main(int argc,char *const argv[]){const char *o[]={"You win!","You lose.","Tie!"};char u, c;srand(time(0));while(u!='q'){printf("Please enter rock/paper/scissors or q to quit: ");u=getchar()|32;while((c=getchar())!='\n');(u=='r'||u=='p'||u=='s')?(printf("%s\n",o[rand()%3])):0;}}
>>
I have an avian based torture fetish.
>>
File: 1446378582393.jpg (39KB, 678x519px) Image search: [Google]
1446378582393.jpg
39KB, 678x519px
>>56251601
winrar
>>
File: 1470614053139.webm (928KB, 426x240px) Image search: [Google]
1470614053139.webm
928KB, 426x240px
I defend myself with crab.
>>
sorry js doesn't have a universal input so interpret the argument as input and its return as output

a=a=>({1: 3, 3: 2, 2: 1}[a]==Math.floor((Math.random() * 3) + 1))?true:(a==Math.floor((Math.random() * 3) + 1))?'tie':false
>>
>>56255335
oh shit, now I have no choicei

import Control.Applicative
import Control.Lens
import Control.Monad.Loops
import System.Random

data RPS = Rock | Paper | Scissors
deriving (Show, Read, Eq, Enum, Bounded)

beats :: RPS -> RPS -> Bool
Rock `beats` Scissors = True
Scissors `beats` Paper = True
Paper `beats` Rock = True
_ `beats` _ = False

instance Random RPS where
randomR (l,h) = over _1 toEnum . randomR (fromEnum l, fromEnum h)
random = randomR (minBound, maxBound)

type Score = (Int, Int)

game :: IO Score
game = iterateUntilM ((>=2) . uncurry max) ?? (0,0) $ \(h,c) -> do
w <- liftA2 beats (read <$> getLine) randomIO
return $ if w then (h+1,c) else (h,c+1)

main = do
(h,c) <- game
putStrLn $ "Human: " ++ show h
putStrLn $ "Computer: " ++ show c
let winner | h > c = "Human" | otherwise = "Computer"
putStrLn $ winner ++ " won!"


best of 3
>>
>>56249424
Kys fucktard
>>
>>56249137
>please do my homework for me
Fuck off and die, useless retard.
>>
>>56249137
joke's on you
i already have
Thread posts: 35
Thread images: 4


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.