Jun-01-2022, 05:35 PM
Hi! I'm new here and I was wondering, I keep on trying different things such as putting in prints in certain points to pinpoint the issue, although the win array is not increasing and for some reason the robot gets more than one turn every round? Even though I tested it and the rmove function only plays once every round... also, the win array returns as all 0, making the move array all -1, if anyone could help this work, that would be great!
and it returns

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 |
x = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] game = [ " " , " " , " " , " " , " " , " " , " " , " " , " " ] igame = [ " " , " " , " " , " " , " " , " " , " " , " " , " " ] win = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] loss = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] move = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] wins = [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 0 , 3 , 6 , 1 , 4 , 7 , 2 , 5 , 8 , 0 , 4 , 8 , 2 , 4 , 6 ] def wincheck(game1): for i in range ( 0 , len (wins), 3 ): if (game1[wins[i]] = = game1[wins[i + 1 ]] = = game1[wins[i + 2 ]] and game1[wins[i]] ! = ""): return game1[wins[i]]; else : for i in range ( 9 ): if (game1[i] = = " " ): break elif (i = = 8 ): return "XO" else : return " " def reset(num1, game1): for i in range (num1 + 1 , 9 ): bool1 = True for i1 in range ( 0 ,num1): if x[i] = = x[i1]: bool1 = False if bool1: game1[x[i]] = " " def pmove(): game[ int ( input ( "Your move: " )) - 1 ] = "O" def rmove(): win = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] loss = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] cmove = 0 ; igame = game for x[ 0 ] in range ( 9 ): reset( 0 ,igame) if igame[x[ 0 ]] = = " " : igame[x[ 0 ]] = "X" else : continue if wincheck(igame) ! = " " : if wincheck(igame) = = "X" : win[x[ 0 ]] + = 1 elif wincheck(igame) = = "O" : loss[x[ 0 ]] + = 1 break for x[ 1 ] in range ( 9 ): reset( 1 ,igame) if igame[x[ 0 ]] = = " " : igame[x[ 0 ]] = "O" else : continue if wincheck(igame) ! = " " : if wincheck(igame) = = "X" : win[x[ 0 ]] + = 1 elif wincheck(igame) = = "O" : loss[x[ 0 ]] + = 1 break for x[ 2 ] in range ( 9 ): reset( 2 ,igame) if igame[x[ 0 ]] = = " " : igame[x[ 0 ]] = "X" else : continue if wincheck(igame) ! = " " : if wincheck(igame) = = "X" : win[x[ 0 ]] + = 1 elif wincheck(igame) = = "O" : loss[x[ 0 ]] + = 1 break for x[ 3 ] in range ( 9 ): reset( 3 ,igame) if igame[x[ 0 ]] = = " " : igame[x[ 0 ]] = "O" else : continue if wincheck(igame) ! = " " : if wincheck(igame) = = "X" : win[x[ 0 ]] + = 1 elif wincheck(igame) = = "O" : loss[x[ 0 ]] + = 1 break for x[ 4 ] in range ( 9 ): reset( 4 ,igame) if igame[x[ 0 ]] = = " " : igame[x[ 0 ]] = "X" else : continue if wincheck(igame) ! = " " : if wincheck(igame) = = "X" : win[x[ 0 ]] + = 1 elif wincheck(igame) = = "O" : loss[x[ 0 ]] + = 1 break for x[ 5 ] in range ( 9 ): reset( 5 ,igame) if igame[x[ 0 ]] = = " " : igame[x[ 0 ]] = "O" else : continue if wincheck(igame) ! = " " : if wincheck(igame) = = "X" : win[x[ 0 ]] + = 1 elif wincheck(igame) = = "O" : loss[x[ 0 ]] + = 1 break for x[ 6 ] in range ( 9 ): reset( 6 ,igame) if igame[x[ 0 ]] = = " " : igame[x[ 0 ]] = "X" else : continue if wincheck(igame) ! = " " : if wincheck(igame) = = "X" : win[x[ 0 ]] + = 1 elif wincheck(igame) = = "O" : loss[x[ 0 ]] + = 1 break for x[ 7 ] in range ( 9 ): reset( 7 ,igame) if igame[x[ 0 ]] = = " " : igame[x[ 0 ]] = "O" else : continue if wincheck(igame) ! = " " : if wincheck(igame) = = "X" : win[x[ 0 ]] + = 1 elif wincheck(igame) = = "O" : loss[x[ 0 ]] + = 1 break for x[ 8 ] in range ( 9 ): reset( 8 ,igame) if igame[x[ 0 ]] = = " " : igame[x[ 0 ]] = "X" else : continue if wincheck(igame) ! = " " : if wincheck(igame) = = "X" : win[x[ 0 ]] + = 1 elif wincheck(igame) = = "O" : loss[x[ 0 ]] + = 1 break igame = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] for i in range ( 0 , len (move)): if win[i]> 0 : move[i] = win[i] / (win[i] + loss[i]) else : move[i] = - 1 print (win[i]) for i in range ( 0 , len (move)): if (move[i] > = move[cmove]): cmove = i game[cmove] = "X" def display(game1): print ( "." + " " + "." + " " + "." + " " + "." ) for i in range ( 3 ): print ( "." + game1[(i * 3 ) + 0 ] + "." + game1[(i * 3 ) + 1 ] + "." + game1[(i * 3 ) + 2 ] + "." ) while True : pmove() rmove() display(game) |
Output:Your move: 1
0
0
0
0
0
0
0
0
0
. . . .
.X. . .
. . . .
. . .X.
Your move: