def __init__(self, p1_starts: bool) -> None: """ Initialize this Game, using p1_starts to find who the first player is. Overrides Game.__init__(self, p1_starts) """ length = input('Please input the side lenght of gameboard:') self.current_state = StonehengeState(p1_starts, int(length))
def __init__(self, p1_starts): """Initializes a game of Stonehenge with side length side_length. @param 'StonehengeGame' self: The current game of Stonehenge @param bool p1_starts: boolean dictating if p1 starts. @rtype: None """ self.side_length = input("What would you like the length " + "of your board to be?") self.p1_starts = p1_starts self.current_state = StonehengeState(int(self.side_length), p1_starts)
def __init__(self, p1_starts: bool) -> None: """ Initialize this Game, using p1_starts to find who the first player is. """ self.p1_starts = p1_starts self.side_length = input('Enter a Number ') while not self.side_length.isdigit(): self.side_length = input('Enter a Number: ') self.side_length = int(self.side_length) if self.side_length >= 6 or self.side_length < 1: raise Exception("Invalid Input!") self.current_state = StonehengeState(self.p1_starts, self.side_length)
def __init__(self, p1_starts: bool) -> None: """ Initialize this Game, using p1_starts to find who the first player is. """ self.p1_starts = p1_starts self.side_length = input('What side length between' ' 1 and 5 inclusive?: ') while not self.side_length.isdigit(): self.side_length = input('What side length between' ' 1 and 5 inclusive?: ') self.side_length = int(self.side_length) if self.side_length >= 6 or self.side_length < 1: raise Exception('Wrong input value') self.current_state = StonehengeState(self.p1_starts, self.side_length)
def __init__(self, p1_starts: bool) -> None: """ Initialize this StonehengeGame, using p1_starts to find who the first player is. :type p1_starts: bool :rtype: None """ self.p1_starts = p1_starts side_length = input("Enter the side length of the board: ") while not (side_length.isdigit() and 0 < int(side_length) <= 5): side_length = input("Enter the side length of the board: ") cells = LETTER[0:calculate_num(int(side_length))] self.current_state = StonehengeState(p1_starts, int(side_length), cells)
def __init__(self, p1_starts: bool) -> None: """ Initialize this Game, using p1_starts to find who the first player is. Precondition: side length <= 5 """ side_length = int(input("Enter the side length of the board: ")) self.current_state = StonehengeState(p1_starts, side_length)
def is_over(self, state: StonehengeState) -> bool: """ Return whether or not this StonehengeGame is over at state. :type state: StonehengeState :rtype: bool """ return state.game_over()
def __init__(self, p1_starts): """ Initialize this Game, using p1_starts to find who the first player is. :param p1_starts: A boolean representing whether Player 1 is the first to make a move. :type p1_starts: bool """ length = int(input("Enter the side length of the board: ")) if length == 1: letter = ["A", "B", "C"] claim = ["@", "@", "@", "@", "@", "@"] elif length == 2: letter = ["A", "B", "C", "D", "E", "F", "G"] claim = ["@", "@", "@", "@", "@", "@", "@", "@", "@"] elif length == 3: letter = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L" ] claim = [ "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@" ] elif length == 4: letter = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R" ] claim = [ "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@" ] elif length == 5: letter = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y" ] claim = [ "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@" ] else: raise NotImplementedError self.current_state = StonehengeState(p1_starts, length, letter, claim)
def __init__(self, is_p1_turn: bool) -> None: """ Initialize a new stonehenge game. """ side_length = int(input("Enter the length of side you wish to play:")) i = 0 alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' self.grid = [] grid = [] for length in range(2, side_length + 2): while length > 0: grid.append(alpha[i]) i += 1 length -= 1 self.grid.append(grid) grid = [] for leng in range(0, side_length): if leng >= 0: grid.append(alpha[i]) i += 1 self.grid.append(grid) self.current_state = StonehengeState(is_p1_turn, self.grid)
def __init__(self, p1_starts: bool, side: str = None) -> None: """ Initialize a stonehenge game. Overrides Game.__init__ >>> game = StonehengeGame(True, '1') >>> repr(game.current_state) == repr(StonehengeState(True, 1)) True """ self.side = input('Enter a size for the stonehenge:') \ if not side else side while not self.side.isdigit(): self.side = input('Enter a size for the stonehenge:') self.current_state = StonehengeState(p1_starts, int(self.side))
class StonehengeGame(Game): """ Abstract class for a game to be played with two players. """ def __init__(self, p1_starts: bool) -> None: """ Initialize this Game, using p1_starts to find who the first player is. """ self.p1_starts = p1_starts self.side_length = input('Enter a Number ') while not self.side_length.isdigit(): self.side_length = input('Enter a Number: ') self.side_length = int(self.side_length) if self.side_length >= 6 or self.side_length < 1: raise Exception("Invalid Input!") self.current_state = StonehengeState(self.p1_starts, self.side_length) def get_instructions(self) -> str: """ Return the instructions for this Game. """ return 'Take turn claiming cells (The capital letters) ' \ 'when a player captures at least half of the cells ' \ 'in a ley line they capture the leyline and the ' \ 'player to capture at least half of all the ' \ 'leylines in game wins!' def is_over(self, state: 'StonehengeState') -> bool: """ Return whether or not this game is over at state. """ count_p2 = 0 count_p1 = 0 even_amount = len(state.ley_line_state) % 2 == 0 for leyline in state.ley_line_state: if state.ley_line_state[leyline] == 1: count_p1 += 1 elif state.ley_line_state[leyline] == 2: count_p2 += 1 if (count_p1 >= len(state.ley_line_state) // 2 or count_p2 >= len(state.ley_line_state) // 2) and \ even_amount: return True elif (count_p1 > len(state.ley_line_state) // 2 or count_p2 > len(state.ley_line_state) // 2) and \ not even_amount: return True return False def is_winner(self, player: str) -> bool: """ Returns which player won the game. """ return (self.current_state.get_current_player_name() != player and self.is_over(self.current_state)) def str_to_move(self, string: str) -> Any: """ Return the move in a form of a string. """ move_list = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' return string.strip() if string in move_list else -1
class StonehengeGame(Game): """ Abstract class for a game to be played with two players. """ def __init__(self, p1_starts): """ Initialize this Game, using p1_starts to find who the first player is. :param p1_starts: A boolean representing whether Player 1 is the first to make a move. :type p1_starts: bool """ length = int(input("Enter the side length of the board: ")) if length == 1: letter = ["A", "B", "C"] claim = ["@", "@", "@", "@", "@", "@"] elif length == 2: letter = ["A", "B", "C", "D", "E", "F", "G"] claim = ["@", "@", "@", "@", "@", "@", "@", "@", "@"] elif length == 3: letter = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L" ] claim = [ "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@" ] elif length == 4: letter = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R" ] claim = [ "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@" ] elif length == 5: letter = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y" ] claim = [ "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@", "@" ] else: raise NotImplementedError self.current_state = StonehengeState(p1_starts, length, letter, claim) def get_instructions(self): """ Return the instructions for this Game. :return: The instructions for this Game. :rtype: str """ instructions = "Players take turns claiming cells (in the diagram: " \ "circles labelled with a capital letter). When a player" \ " captures at least half of the cells in a ley-line " \ ", then the player captures that ley-line." \ " The first player to capture at least half of the " \ "ley-lines is the winner. A ley-line, once claimed," \ " cannot be taken by the other player." return instructions def is_over(self, state): """ Return whether or not this game is over. :return: True if the game is over, False otherwise. :rtype: bool """ if state.p1_turn: name = '2' else: name = '1' count = 0 for i in state.claim: if i == name: count += 1 return (state.get_possible_moves() == []) or \ (count >= 0.5 * len(state.claim)) def is_winner(self, player): """ Return whether player has won the game. Precondition: player is 'p1' or 'p2'. :param player: The player to check. :type player: str :return: Whether player has won or not. :rtype: bool """ # (self.current_state.get_current_player_name() == player # and return (self.current_state.get_current_player_name() != player and self.is_over(self.current_state)) def str_to_move(self, string): """ Return the move that string represents. If string is not a move, return an invalid move (for example, "0" ). :param string: :type string: :return: :rtype: """ if not string.strip().isalpha(): return 0 return string
class StonehengeGame(Game): """A class representing the game of Stonehenge, inheriting from Game and implementing all its methods. """ def __init__(self, p1_starts): """Initializes a game of Stonehenge with side length side_length. @param 'StonehengeGame' self: The current game of Stonehenge @param bool p1_starts: boolean dictating if p1 starts. @rtype: None """ self.side_length = input("What would you like the length " + "of your board to be?") self.p1_starts = p1_starts self.current_state = StonehengeState(int(self.side_length), p1_starts) def get_instructions(self): """Returns a string containing the instructions on how to play the game. """ return "The game is played by each of the two players claiming " \ "a cell, which then changes from representing an alphabet" \ "to representing the number of the player that captured it." \ "When more than half the cells in a line have been claimed" \ "by a single user, the ley-line is claimed by the " \ "user completely." \ "when more than half the ley-lines have been claimed by " \ "a player, the player wins." def is_over(self, currentstate: 'GameState') -> bool: """Returns True iff according to the current_state, the game ends. @param 'StonehengeGame' self: the current game of Stonehenge @param Any currentstate: the current state of the game of Stonehenge @rtype: bool """ leyline_list = [d.head for d in currentstate.board.leyline_tracker] total_length = 3 * (int(self.side_length) + 1) if leyline_list.count(1) >= total_length / 2: return True elif leyline_list.count(2) >= total_length / 2: return True elif '@' not in leyline_list: return True return False def is_winner(self, player: str): """Returns True if the player player is the winner of the game. @param 'StonehengeGame' self: The current game of Stonehenge @param str player: the player being entered to check if he/she is the winner. @rtype: bool """ headlist = [c.head for c in self.current_state.board.leyline_tracker] if player == 'p1': if headlist.count(1) >= len(headlist) / 2: # checks if the number of leylines claimed by p1 is more than # half the number of total leylines return True elif "@" not in headlist and headlist.count(1) > headlist.count(2): # checks that if all leylines are claimed, then the ones claimed # by p1 are more than the ones claimed by p2 return True return False elif player == 'p2': if headlist.count(2) >= len(headlist) / 2: # checks if the number of leylines claimed by p2 is more than # half the number of total leylines return True elif "@" not in headlist and headlist.count(2) > headlist.count(1): # checks that if all leylines are claimed, then the ones claimed # by p2 are more than the ones claimed by p1 return True return False return False def str_to_move(self, move: str) -> Any: """Returns a valid move based on the inputted string. If the inputted string represents an invalid move, return an invalid move. @param 'StonehengeGame' self: The current game of Stonehenge @param str move: The entered string representing a valid or an invalid move @rtype: Any """ if move.upper() in self.current_state.get_possible_moves(): return move.upper()
class StonehengeGame(Game): """ Game stonehenge which to be played with two players. """ def __init__(self, is_p1_turn: bool) -> None: """ Initialize a new stonehenge game. """ side_length = int(input("Enter the length of side you wish to play:")) i = 0 alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' self.grid = [] grid = [] for length in range(2, side_length + 2): while length > 0: grid.append(alpha[i]) i += 1 length -= 1 self.grid.append(grid) grid = [] for leng in range(0, side_length): if leng >= 0: grid.append(alpha[i]) i += 1 self.grid.append(grid) self.current_state = StonehengeState(is_p1_turn, self.grid) def get_instructions(self) -> str: """ Return the instruction of the game """ return "Players take turns claiming cells. When a player captures" \ " at least half of the cells in a ley-line, then player" \ " captures the ley-line. Player wins when captures at" \ " least half of the lay-lines." def is_over(self, state: StonehengeState) -> bool: """ Return whether or not this game is over. """ p1score = 0 p2score = 0 check = len(state.at) / 2 for item in state.at: if state.at[item] == 1: p1score += 1 elif state.at[item] == 2: p2score += 1 return p1score >= check or p2score >= check def is_winner(self, player: str) -> bool: """ Return whether player has won the game. """ return (self.is_over(self.current_state) and self.current_state.get_current_player_name() != player) def str_to_move(self, string: str) -> str: """ Return the move in the format that wanted. """ if not string.strip().isalpha() or len(string) != 1: return 'Z' return string.strip().upper()
class StonehengeGame(Game): """ Abstract class for a game to be played with two players. """ def __init__(self, p1_starts: bool) -> None: """ Initialize this Game, using p1_starts to find who the first player is. """ self.p1_starts = p1_starts self.side_length = input('What side length between' ' 1 and 5 inclusive?: ') while not self.side_length.isdigit(): self.side_length = input('What side length between' ' 1 and 5 inclusive?: ') self.side_length = int(self.side_length) if self.side_length >= 6 or self.side_length < 1: raise Exception('Wrong input value') self.current_state = StonehengeState(self.p1_starts, self.side_length) def get_instructions(self) -> str: """ Return the instructions for this Game. """ instructions = 'Take turn claiming cells (The capital letters) ' \ 'when a player captures at least half of the cells ' \ 'in a ley line they capture the leyline and the ' \ 'player to capture at least half of all the ' \ 'leylines in game wins!' return instructions def is_over(self, state: 'StonehengeState') -> bool: """ Return whether or not this game is over at state. """ count_claimed_p2 = 0 count_claimed_p1 = 0 even_amount = len(state.ley_line_state) % 2 == 0 for leyline in state.ley_line_state: if state.ley_line_state[leyline] == 1: count_claimed_p1 += 1 elif state.ley_line_state[leyline] == 2: count_claimed_p2 += 1 if (count_claimed_p1 >= len(state.ley_line_state) // 2 or count_claimed_p2 >= len(state.ley_line_state) // 2) and \ even_amount: return True elif (count_claimed_p1 > len(state.ley_line_state) // 2 or count_claimed_p2 > len(state.ley_line_state) // 2) and \ not even_amount: return True return False def is_winner(self, player: str) -> bool: """ Return whether player has won the game. Precondition: player is 'p1' or 'p2'. """ return (self.current_state.get_current_player_name() != player and self.is_over(self.current_state)) def str_to_move(self, string: str) -> Any: """ Return the move that string represents. If string is not a move, return some invalid move. """ alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' return string.strip() if string in alphabet else -1
def is_over(self, state: StonehengeState)-> bool: """ Return whether or not this game is over. """ return state.state_over()
class StonehengeGame(Game): """ Abstract class for a game to be played with two players. length: side length of a StonehengeGame that the player input current_state: the current game state of a StonehengeGame """ length: int current_state: StonehengeState def __init__(self, p1_starts: bool) -> None: """ Initialize this Game, using p1_starts to find who the first player is. Overrides Game.__init__(self, p1_starts) """ length = input('Please input the side lenght of gameboard:') self.current_state = StonehengeState(p1_starts, int(length)) def __eq__(self, other: Any) -> bool: """ Return whether StonehengeGame self is equivalent to other. """ return (type(self) == type(other) and self.current_state == other.current_state and self.length == other.length) def __str__(self) -> str: """ Return a string representation of the StonehengeGame self. """ return self.current_state.__str__() def get_instructions(self) -> str: """ Return the instructions of this game. Overrrides Game.get_instructions(self) """ instructions = "Stonehenge is played on a hexagonal grid formed by " \ 'removing the corners from a triangular grid. Boards ' \ 'can ' \ 'have various sizes based on their side-length (the ' \ 'number of cells in the grid along the bottom), but ' \ 'are ' \ 'always formed in a similar manner: For ' \ 'side-length n, ' \ 'the first row has 2 cells, and each row after has 1 ' \ "additional cell up until there's a row with n + 1 " \ "cells, after which the last row has only n cells in " \ "it. \n Players take turns claiming cells (in the " \ "diagram: circles labelled with a capital letter). " \ "When a player captures at least half of the cells " \ "in a " \ "ley-line (in the diagram: hexagons with a line " \ "connecting it to cells), then the player captures " \ "that ley-line. The first player to capture at least" \ " half " \ "of the ley-lines is the winner. A ley-line, once " \ "claimed, cannot be taken by the other player." return instructions def is_over(self, state: StonehengeState) -> bool: """ Return whether or not this game is over. Override Game.is_over(self) """ result = False if (state.p1_count / state.total_leylines >= 0.5 or state.p2_count / state.total_leylines >= 0.5 or self.current_state.get_possible_moves() == []): result = True return result def is_winner(self, player: str) -> bool: """ Return whether player has won the game. Precondition: player is 'p1' or 'p2'. Override Game.is_winner(self) """ return (self.current_state.get_current_player_name() != player and self.is_over(self.current_state)) def str_to_move(self, move_to_make: Any) -> str: """ Return the move that string represents. If string is not a move, return an invalid move. Override Game.str_to_move(self, string) """ result = str(move_to_make).upper().strip() while not result.isalpha() or len(result) != 1: result = input('Please enter a valid move:') self.string_to_move(result) return result
def __init__(self, p1_starts): """ Initialize this Game, using p1_starts to find who the first player is. :param p1_starts: A boolean representing whether Player 1 is the first to make a move. :type p1_starts: bool """ dic1 = { "h": [["@", "A", "B"], ["@", "C"]], "d1": [["@", "A"], ["@", "B", "C"]], "d2": [["@", "C", "A"], ["@", "B"]] } board1 = (" {} {}\n" " / /\n" "{} - {} - {}\n" " \\ / \\\n" " {} - {} {}\n" " \\\n {}".format( dic1["d1"][0][0], dic1["d1"][1][0], dic1["h"][0][0], dic1["h"][0][1], dic1["h"][0][2], dic1["h"][1][0], dic1["h"][1][1], dic1["d2"][1][0], dic1["d2"][0][0])) dic2 = { "h": [["@", "A", "B"], ["@", "C", "D", "E"], ["@", "F", "G"]], "d1": [["@", "A", "C"], ["@", "B", "D", "F"], ["@", "E", "G"]], "d2": [["@", "F", "C"], ["@", "G", "D", "A"], ["@", "E", "B"]] } board2 = (' {} {}\n' ' / /\n' ' {} - {} - {} {}\n' ' / \ / \ /\n' '{} - {} - {} - {}\n' ' \ / \ / \ \n' ' {} - {} - {} {}\n' ' \ \ \n' ' {} {}'.format(dic2["d1"][0][0], dic2["d1"][1][0], dic2["h"][0][0], dic2["h"][0][1], dic2["h"][0][2], dic2["d1"][2][0], dic2["h"][1][0], dic2["h"][1][1], dic2["h"][1][2], dic2["h"][1][3], dic2["h"][2][0], dic2["h"][2][1], dic2["h"][2][2], dic2['d2'][2][0], dic2["d2"][0][0], dic2["d2"][1][0])) dic3 = { "h": [["@", "A", "B"], ["@", "C", "D", "E"], ["@", "F", "G", "H", "I"], ["@", "J", "K", "L"]], "d1": [["@", "A", "C", "F"], ["@", "B", "D", "G", "J"], ["@", "E", "H", "K"], ["@", "I", "L"]], "d2": [["@", "J", "F"], ["@", "K", "G", "C"], ["@", "L", "H", "D", "A"], ["@", "I", "E", "B"]] } board3 = (' {} {}\n' ' / /\n' ' {} - {} - {} {}\n' ' \ / \ / \ / \n' ' {} - {} - {} - {} {}\n' ' / \ / \ / \ /\n' '{} - {} - {} - {} - {}\n' ' \ / \ / \ / \ \n' ' {} - {} - {} - {} {} \n' ' \ \ \ \n' ' {} {} {}\n'.format( dic3["d1"][0][0], dic3["d1"][1][0], dic3["h"][0][0], dic3['h'][0][1], dic3["h"][0][2], dic3["d1"][2][0], dic3["h"][1][0], dic3["h"][1][1], dic3["h"][1][2], dic3["h"][1][3], dic3["d2"][3][0], dic3["h"][2][0], dic3["h"][2][1], dic3["h"][2][2], dic3["h"][2][3], dic3["h"][2][4], dic3["h"][3][0], dic3["h"][3][1], dic3["h"][3][2], dic3["h"][3][3], dic3['d2'][3][0], dic3["d2"][0][0], dic3["d2"][1][0], dic3["d2"][2][0], )) dic4 = { "h": [["@", "A", "B"], ["@", "C", "D", "E"], ["@", "F", "G", "H", "I"], ["@", "J", "K", "L", "M", "N"], ["@", "O", "P", "Q", "R"]], "d1": [["@", "A", "C", "F", "J"], ["@", "B", "D", "G", "K", "O"], ["@", "E", "H", "L", "P"], ["@", "I", "M", "Q"], ["@", "N", "R"]], "d2": [["@", "O", "J"], ["@", "P", "K", "F"], ["@", "Q", "L", "G", "C"], ["@", "R", "M", "H", "D", "A"], ["@", "N", "I", "E", "B"]] } board4 = (" {} {}\n" " / /\n" " {} - {} - {} {}\n" " \ / \ / \ / \n" " {} - {} - {} - {} {}\n" " / \ / \ / \ /\n" " {} - {} - {} - {}- {} {}\n" " / \ / \ / \ / \ / \n" "{} - J - K - L - M - N\n" " \ / \ / \ / \ / \ \n" " @ - O - P - Q - R @\n" " \ \ \ \ \n" " @ @ @ @\n".format( dic4["d1"][0][0], dic4["d1"][1][0], dic4["h"][0][0], dic4['h'][0][1], dic4["h"][0][2], dic4["d1"][2][0], dic4["h"][1][0], dic4["h"][1][1], dic4["h"][1][2], dic4["h"][1][3], dic4["d1"][3][0], dic4["h"][2][0], dic4["h"][2][1], dic4["h"][2][2], dic4["h"][2][3], dic4["h"][2][4], dic4["d1"][4][0], dic4["h"][3][0], dic4["h"][3][1], dic4["h"][3][2], dic4["h"][3][3], dic4["h"][3][4], dic4["h"][3][5], dic4["h"][4][0], dic4["h"][4][1], dic4["h"][4][2], dic4["h"][4][3], dic4["h"][4][4], dic4['d2'][4][0], dic4["d2"][0][0], dic4["d2"][1][0], dic4["d2"][2][0], dic4["d2"][3][0], )) dic = { 1: [board1, dic1], 2: [board2, dic2], 3: [board3, dic3], 4: [board4, dic4] } len_game = '' self.length = int(input("Enter the length of stonehenge: ")) for x in dic: if x == self.length: len_game = dic[x] self.current_state = StonehengeState(p1_starts, len_game[0], len_game[1], self.length)
class StonehengeGame(Game): """ Abstract class for a game called Stonehenge, to be played with two players. === Attributes === is_p1_turn - whether it is p1's turn, if not, then it is p2's turn. current_state - the current state of the game StonehengeGame. """ def __init__(self, p1_starts: bool) -> None: """ Initialize this StonehengeGame, using p1_starts to find who the first player is. :type p1_starts: bool :rtype: None """ self.p1_starts = p1_starts side_length = input("Enter the side length of the board: ") while not (side_length.isdigit() and 0 < int(side_length) <= 5): side_length = input("Enter the side length of the board: ") cells = LETTER[0:calculate_num(int(side_length))] self.current_state = StonehengeState(p1_starts, int(side_length), cells) def get_instructions(self) -> str: """ Return the instructions for this StonehengeGame. :rtype: str """ return " Players take turns claiming cells (in the diagram: circles " \ "labelled with a capital letter). When a player captures at " \ "least half of the cells in a ley-line (in the diagram: " \ "hexagons with a line connecting it to cells), then the player" \ "captures that ley-line. The rst player to capture at least " \ "half of the ley-lines is the winner. A ley-line, once " \ "claimed cannot be taken by the other player." def is_over(self, state: StonehengeState) -> bool: """ Return whether or not this StonehengeGame is over at state. :type state: StonehengeState :rtype: bool """ return state.game_over() def is_winner(self, player: str) -> bool: """ Return whether player has won the game. Precondition: player is 'p1' or 'p2'. :type player:str :rtype:bool """ if self.is_over(self.current_state): if self.current_state.p1_turn: return player == 'p2' return player == 'p1' return False def str_to_move(self, move_to_make: str) -> str: """ Return the move that string represents, in this game, want to return capitalized letter of move_to_make. If move_to_make is not a move, return some invalid move. """ if move_to_make in self.current_state.get_possible_moves(): return move_to_make.upper() return "Invalid move."