示例#1
0
 def test_make_two_players(self):
     user_input = ["Austin", "P", "Bob", "X"]
     with patch('ConnectNGame.src.game.input', side_effect=user_input):
         a = Game(3, 3, 3, "O")
         a.make_two_players()
         self.assertEqual(a.player1.name, "Austin")
         self.assertEqual(a.player2.name, "Bob")
         self.assertEqual(a.player1.piece, "P")
         self.assertEqual(a.player2.piece, "X")
示例#2
0
 def test_initialize_game(self):
     capture = PrintCapturer()
     with patch('ConnectNGame.src.game.print', side_effect=capture):
         a = Game(3, 3, 3, "x")
         a.initialize_game()
         board_output = "  0 1 2\n" \
                        "0 x x x\n" \
                        "1 x x x\n" \
                        "2 x x x\n"
         self.assertEqual(board_output, capture.as_string())
示例#3
0
 def test_check_for_win_horizontal(self):
     a = Game(3, 3, 3, "x")
     a.initialize_game()
     a._place_piece(2, "P")
     a._place_piece(1, "P")
     a._place_piece(0, "P")
     self.assertEqual(a._check_for_win("P"), True)
示例#4
0
 def test_wrong_input_for_make_two_players(self):
     user_input = [
         "   ", "Kobe", "dog", "Kobe", "X", "Juice", "X", "Juice", "L"
     ]
     with patch('ConnectNGame.src.game.input', side_effect=user_input):
         a = Game(3, 3, 3, "O")
         a.make_two_players()
         self.assertEqual(a.player1.name, "Kobe")
         self.assertEqual(a.player2.name, "Juice")
         self.assertEqual(a.player1.piece, "X")
         self.assertEqual(a.player2.piece, "L")
示例#5
0
def main() -> None:
    config_dict: Dict[str, str] = {}
    config_file = sys.argv[1]
    with open(config_file) as file:
        for line in file:
            line = line.split(":")  # type: ignore
            key = line[0]
            key = key.strip()
            value = line[1]
            value = value.strip()
            config_dict[key] = value

    num_rows = int(config_dict["num_rows"])
    num_columns = int(config_dict["num_cols"])
    num_pieces_to_win = int(config_dict["num_pieces_to_win"])
    blank_char = config_dict["blank_char"]
    play_game = Game(num_rows, num_columns, num_pieces_to_win, blank_char)
    play_game.make_two_players()
    play_game.initialize_game()
    play_game.play()
示例#6
0
 def test_check_for_win_left_diagonal(self):
     a = Game(3, 3, 3, "x")
     a.initialize_game()
     a._place_piece(0, "O")
     a._place_piece(1, "X")
     a._place_piece(1, "O")
     a._place_piece(2, "X")
     a._place_piece(2, "O")
     a._place_piece(1, "X")
     a._place_piece(2, "O")
     self.assertEqual(a._check_for_win("O"), True)