def checkwin(board): #check if someone has won curboard = 0 if isinstance(board,GameBoard): #typechecking is not working consistently. curboard = board elif isinstance(board, list): curboard = GameBoard(board) else: return 1 #SOMETHING WENT WRONG. if( #horizontals (curboard.is1(0,0) and curboard.is1(0,1) and curboard.is1(0,2)) or (curboard.is1(1,0) and board.is1(1,1) and curboard.is1(1,2)) or (curboard.is1(2,0) and curboard.is1(2,1) and curboard.is1(2,2)) or #verticals (curboard.is1(0,0) and curboard.is1(1,0) and curboard.is1(2,0)) or (curboard.is1(0,1) and curboard.is1(1,1) and curboard.is1(2,1)) or (curboard.is1(0,2) and curboard.is1(1,2) and curboard.is1(2,2)) or #diagonals (curboard.is1(0,0) and curboard.is1(1,1) and curboard.is1(2,2)) or (curboard.is1(0,2) and curboard.is1(1,1) and curboard.is1(2,0)) ): return 1 #1 wins elif ( #horizontals (curboard.is2(0,0) and curboard.is2(0,1) and curboard.is2(0,2)) or (curboard.is2(1,0) and curboard.is2(1,1) and curboard.is2(1,2)) or (curboard.is2(2,0) and curboard.is2(2,1) and curboard.is2(2,2)) or #verticals (curboard.is2(0,0) and curboard.is2(1,0) and curboard.is2(2,0)) or (curboard.is2(0,1) and curboard.is2(1,1) and curboard.is2(2,1)) or (curboard.is2(0,2) and curboard.is2(1,2) and curboard.is2(2,2)) or #diagonals (curboard.is2(0,0) and curboard.is2(1,1) and curboard.is2(2,2)) or (curboard.is2(0,2) and curboard.is2(1,1) and curboard.is2(2,0)) ): return 2 # 2 wins else: has_valid_move = False for i in range(3): for j in range(3): if not curboard.is1(i,j) and not curboard.is2(i,j): has_valid_move = True break; if has_valid_move: break; if has_valid_move: return 0 # keep going else: return -1 # draw.
def __init__(self): self._atom_list = sample(list(product(range( 1, 9), repeat=2)), k=5) # initialize random list of atom locations self._gameB = GameBoard( self._atom_list) # initialize a game board with the atom list self._board = self._gameB.get_board( ) # get the game board for calculating ray path self._score = 25 # initialize the starting points for the game self._ray_locations = [] # empty list to store ray entry/exit squares self._wrong_atom_guesses = [ ] # empty list to store incorrect atom guesses self._correct_atom_guesses = [ ] # empty list to store correct atom guesses self._ray_status = None self._ray_row = None self._ray_column = None self._screen = pygame.display.set_mode((600, 800)) self._font = pygame.font.Font('freesansbold.ttf', 36) self.background = pygame.image.load('board_grid.png') self.background = pygame.transform.scale(self.background, (600, 600)) self._game_status = True self._ray_color = None
def __init__(self): self.__game_board = GameBoard() self.__opponent_map = GameBoard() self.__game_board.populate_board()
def __init__(self, Player1, Player2): self.player1 = Player1 self.player2 = Player2 self.board = GameBoard() self.turn = 1
#################### # Load Configuration File #################### configuration_path = sys.argv[1] with open(configuration_path) as f: try: lines = f.readlines() board_size = lines[0].replace("\n", "").split(" ") ship_data_array = [] for x in lines[1:]: ship_data = x.replace("\n", "").split(" ") ship_data[1] = int(ship_data[1]) ship_data_array.append(tuple(ship_data)) board1 = GameBoard(board_size) board2 = GameBoard(board_size) except: print("Some error is in the configuration file. Please check the file.") sys.exit() #################### # Create Players and Ships #################### # player1_name = input("Player 1 please enter your name: ") player1 = Player(player1_name, board1) for shipData in ship_data_array: name = shipData[0]
from Board import GameBoard from HumanPlayer import HumanPlayer from DumbAI import DumbAI from SmartAI import SmartAI # draw board # while not game finished # get player move # redraw board # check for game over board = GameBoard() player1 = SmartAI("SmartAI", 'O', board) player2 = DumbAI("DumbAI", 'X') players = [player1, player2] for i in range(0, 100): print(i) board.reset() while board.game_over() == 0: for player in players: move = player.get_move() while board.submit_move(move) != 1: move = player.get_move() if board.game_over() != 0: if board.game_over() != 'TIE': player.Winner() break