

Link: http://codepad.org/G8O3q2pd raw code | output | fork ]



Python , pasted on Aug 23:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 # Python 2.7 # Copyright the fat kid who sat next to me in 4th grade and enjoyed playing rock, paper, scissors. #This code is ugly, but I had fun writing it. #Please port it to other languages if you wish, would be fun to compare. #Pablo_ipc """ Game has a player (com_A) against an opponent that can change strategies depending on the score (com_(B,C,D,E)), it is currently not using more than 2 strategies. """ import random # player and opponents basics defined in functions def com_A (): num_choice = random . randint ( 1 , 3 ) #numerical choice to represent string choice com_A = "" #computer choice: rock, paper or scissor. if num_choice == 1 : com_A = "rock" if num_choice == 2 : com_A = "paper" if num_choice == 3 : com_A = "scissors" return com_A def com_B (): """com_B random version. Works exactly as com_A """ num_choice = random . randint ( 1 , 3 ) #numerical choice to represent string choice com_B = "" #computer choice: rock, paper or scissor. if num_choice == 1 : com_B = "rock" if num_choice == 2 : com_B = "paper" if num_choice == 3 : com_B = "scissors" return com_B def com_C (): """com_C always plays rock. """ com_C = "rock" return com_C def com_D (): """com_D always plays paper. """ com_D = "rock" return com_D def com_E (): """com_E always plays rock. """ com_E = "scissors" return com_E ######################################## #game score basics defined game_count = 0 #keeps track of how many games have been played. game_score_player = 0 #game score for com_A, which is the player. game_score_opponent = 0 #com_(B, C, D, E) score ends here. These are the opponents. ######################################## #stats #player stats P_rock = 0 P_paper = 0 P_scissors = 0 #opponent stats O_rock = 0 O_paper = 0 O_scissors = 0 ######################################## #game while game_count <= 99 : #main loop game_count += 1 #random vs. constant ## player = com_A() #uncomment to play with different logic ## opponent = com_E() ## #random vs. random #uncomment to play with different logic ## player = com_A() ## opponent = com_B() #random vs. random, unless opponent is losing, it switches to constant until it is winning again. Like Charlie Sheen. player = com_A () if game_score_opponent >= game_score_player : #if its winning plays with com_B opponent = com_B () print "com_B is playing now." if game_score_opponent <= game_score_player : #if its losing it plays with com_C until it is winning and changes to com_B opponent = com_C () print "Switched to com_C." #end of logic if player == "scissors" and opponent == "paper" : game_score_player += 1 P_scissors += 1 O_paper += 1 print "Player:" , player , "Opponent:" , opponent if player == "rock" and opponent == "scissors" : game_score_player += 1 P_rock += 1 O_scissors += 1 print "Player:" , player , "Opponent:" , opponent if player == "paper" and opponent == "rock" : game_score_player += 1 P_paper += 1 O_rock += 1 print "Player:" , player , "Opponent:" , opponent if player == "paper" and opponent == "scissors" : game_score_opponent += 1 P_paper += 1 O_scissors += 1 print "Player:" , player , "Opponent:" , opponent if player == "scissors" and opponent == "rock" : game_score_opponent += 1 P_scissors += 1 O_rock += 1 print "Player:" , player , "Opponent:" , opponent if player == "rock" and opponent == "paper" : game_score_opponent += 1 P_rock += 1 O_paper += 1 print "Player:" , player , "Opponent:" , opponent ######################### #game stats if game_score_player > game_score_opponent : print "Player wins with:" , game_score_player , "points." print "Opponent had: " , game_score_opponent , "points." print "

There were" , game_count , "games played." print "Player played rock" , P_rock , "times, paper" , P_paper , "times, and scissors" , P_scissors , "times." print "Opponent played rock" , O_rock , "times, paper" , O_paper , "times, and scissors" , O_scissors , "times." total_played = P_rock + P_paper + P_scissors ties = 100 - total_played print "There were" , total_played , "games won total." print "there were" , ties , "ties." if game_score_player < game_score_opponent : print "Opponent wins with:" , game_score_opponent , "points." print "Player had: " , game_score_player , "points." print "

There were" , game_count , "games played." print "Player played rock" , P_rock , "times, paper" , P_paper , "times, and scissors" , P_scissors , "times." print "Opponent played rock" , O_rock , "times, paper" , O_paper , "times, and scissors" , O_scissors , "times." total_played = P_rock + P_paper + P_scissors ties = 100 - total_played print "There were" , total_played , "games won total." print "There were" , ties , "ties."



Output: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 com_B is playing now. Switched to com_C. Player: paper Opponent: rock Switched to com_C. Player: scissors Opponent: rock com_B is playing now. Switched to com_C. Player: scissors Opponent: rock com_B is playing now. Player: paper Opponent: rock com_B is playing now. Switched to com_C. com_B is playing now. Switched to com_C. Player: paper Opponent: rock Switched to com_C. Player: scissors Opponent: rock com_B is playing now. Switched to com_C. Player: scissors Opponent: rock com_B is playing now. Player: rock Opponent: paper com_B is playing now. com_B is playing now. Player: paper Opponent: scissors com_B is playing now. Player: scissors Opponent: paper com_B is playing now. Player: paper Opponent: scissors com_B is playing now. Player: rock Opponent: paper com_B is playing now. com_B is playing now. Player: rock Opponent: scissors com_B is playing now. com_B is playing now. com_B is playing now. Player: rock Opponent: paper com_B is playing now. Player: paper Opponent: rock com_B is playing now. com_B is playing now. Player: scissors Opponent: rock com_B is playing now. Player: rock Opponent: scissors com_B is playing now. com_B is playing now. com_B is playing now. Player: paper Opponent: scissors com_B is playing now. Player: rock Opponent: scissors com_B is playing now. Player: scissors Opponent: rock com_B is playing now. Player: paper Opponent: rock com_B is playing now. Player: rock Opponent: paper com_B is playing now. Player: rock Opponent: scissors com_B is playing now. Player: scissors Opponent: paper com_B is playing now. Player: rock Opponent: paper com_B is playing now. com_B is playing now. Player: rock Opponent: paper com_B is playing now. com_B is playing now. com_B is playing now. Player: scissors Opponent: rock com_B is playing now. Player: rock Opponent: scissors com_B is playing now. com_B is playing now. Player: rock Opponent: scissors com_B is playing now. com_B is playing now. Player: paper Opponent: scissors com_B is playing now. Player: scissors Opponent: rock com_B is playing now. Player: scissors Opponent: paper com_B is playing now. com_B is playing now. com_B is playing now. Player: rock Opponent: paper com_B is playing now. Player: scissors Opponent: rock com_B is playing now. Player: rock Opponent: paper com_B is playing now. com_B is playing now. Player: scissors Opponent: paper com_B is playing now. Player: rock Opponent: paper com_B is playing now. com_B is playing now. Player: rock Opponent: scissors com_B is playing now. Player: scissors Opponent: paper com_B is playing now. com_B is playing now. Player: scissors Opponent: rock com_B is playing now. Player: paper Opponent: scissors com_B is playing now. Player: rock Opponent: paper com_B is playing now. Player: scissors Opponent: rock com_B is playing now. Player: scissors Opponent: paper com_B is playing now. Player: scissors Opponent: rock com_B is playing now. Player: paper Opponent: scissors com_B is playing now. Player: paper Opponent: scissors com_B is playing now. Player: paper Opponent: scissors com_B is playing now. Player: rock Opponent: scissors com_B is playing now. Player: rock Opponent: paper com_B is playing now. com_B is playing now. com_B is playing now. Player: scissors Opponent: rock com_B is playing now. Player: scissors Opponent: paper com_B is playing now. com_B is playing now. Player: scissors Opponent: paper com_B is playing now. Player: scissors Opponent: paper com_B is playing now. Player: rock Opponent: paper com_B is playing now. com_B is playing now. com_B is playing now. Player: rock Opponent: scissors com_B is playing now. Player: paper Opponent: rock com_B is playing now. com_B is playing now. Player: paper Opponent: rock com_B is playing now. Player: rock Opponent: paper com_B is playing now. com_B is playing now. Player: rock Opponent: paper com_B is playing now. com_B is playing now. com_B is playing now. Player: scissors Opponent: paper com_B is playing now. Player: scissors Opponent: rock com_B is playing now. Player: rock Opponent: scissors com_B is playing now. Player: paper Opponent: rock com_B is playing now. com_B is playing now. Player: scissors Opponent: paper com_B is playing now. Player: rock Opponent: scissors com_B is playing now. Player: scissors Opponent: rock com_B is playing now. com_B is playing now. Player: paper Opponent: rock com_B is playing now. com_B is playing now. Player: rock Opponent: paper com_B is playing now. Player: paper Opponent: scissors Opponent wins with: 39 points. Player had: 31 points. There were 100 games played. Player played rock 26 times, paper 18 times, and scissors 26 times. Opponent played rock 24 times, paper 26 times, and scissors 20 times. There were 70 games won total. There were 30 ties.