def auto_play(self): import game self.matrix = game.init_matrix() while not game.is_over(self.matrix): print('') game.print_matrix(self.matrix) move, _score = self.find_best_move() print("best move:", move, 'with score: ', _score) _matrix = move(self.matrix) if _matrix == self.matrix: print("invalid move, nothing changed.") else: self.matrix = game.random_insert(_matrix)
def game_fun(): print("\nYour Move:") x = int(raw_input("Enter the row number: ")) y = int(raw_input("Enter the coloumn number: ")) #test if it is a hit if (player2[x][y] == 'C' or player2[x][y] == 'B' or player2[x][y] == 'R' or player2[x][y] == 'S' or player2[x][y] == 'D'): print("You hit a ship") player2[x][y] = 'X' matrix2[x][y] = 'H' #check if the game is over or if a ship is completely destroyed if game.search(2, player2) == 1: exit(1) else: print("You missed") matrix2[x][y] = 'M' time.sleep(0.5) update_shipstate1() game.print_matrix(matrix3, matrix2)
def ai_play(): step = 0 matrix = game.init_matrix() moves = [game.move_up, game.move_down, game.move_left, game.move_right] while not game.is_over(matrix): game.print_matrix(matrix) best_move, best_score = find_best_move(matrix) if best_move == -1: print('cannot find best move, quit game.') break matrix = moves[best_move](matrix) print('step %4d the best move is %4s, the score %5d' % \ (step, ['up', 'down', 'left', 'right'][best_move], best_score)) matrix = game.random_insert(matrix) step += 1 return
Destroyer 4 D 2 """ for i in range(0, 10): for j in range(0, 10): player1[i][j] = txt2.read(1) char = txt2.read(1) for i in range(0, 10): for j in range(0, 10): ship_player1[i][j] = player1[i][j] '''for i in range(0,10): for j in range(0,10): print "%c "%ship_player1[i][j], print "\n"''' game.print_matrix(matrix3, matrix2) time.sleep(0.5) count_moves = 0 def game_fun(): print("\nYour Move:") x = int(raw_input("Enter the row number: ")) y = int(raw_input("Enter the coloumn number: ")) #test if it is a hit if (player2[x][y] == 'C' or player2[x][y] == 'B' or player2[x][y] == 'R' or player2[x][y] == 'S' or player2[x][y] == 'D'): print("You hit a ship") player2[x][y] = 'X' matrix2[x][y] = 'H' #check if the game is over or if a ship is completely destroyed