Esempio n. 1
0
def test_set_initial_position(tc):
    board = ascii_boards.interpret_diagram(DIAGRAM1, 9)
    sgf_game = sgf.Sgf_game(9)
    sgf_moves.set_initial_position(sgf_game, board)
    root = sgf_game.get_root()
    tc.assertEqual(root.get("AB"), set([(0, 0), (1, 1), (4, 4)]))
    tc.assertEqual(root.get("AW"), set([(6, 5), (6, 6)]))
    tc.assertRaises(KeyError, root.get, 'AE')
Esempio n. 2
0
def test_interpret_diagram(tc):
    b1 = boards.Board(9)
    b1.play(2, 3, 'b')
    b1.play(3, 4, 'w')
    b2 = ascii_boards.interpret_diagram(_9x9_expected, 9)
    tc.assertEqual(b1, b2)
    b3 = boards.Board(9)
    b4 = ascii_boards.interpret_diagram(_9x9_expected, 9, b3)
    tc.assertIs(b3, b4)
    tc.assertEqual(b1, b3)
    tc.assertRaisesRegexp(ValueError, "board not empty",
                          ascii_boards.interpret_diagram, _9x9_expected, 9, b3)
    b5 = boards.Board(19)
    tc.assertRaisesRegexp(ValueError, "wrong board size, must be 9$",
                          ascii_boards.interpret_diagram, _9x9_expected, 9, b5)

    tc.assertRaises(ValueError, ascii_boards.interpret_diagram, "nonsense", 9)
    b6 = ascii_boards.interpret_diagram(_13x13_expected, 13)
    tc.assertDiagramEqual(ascii_boards.render_board(b6), _13x13_expected)
Esempio n. 3
0
def test_game_score_from_position(tc):
    board = ascii_boards.interpret_diagram(DIAGRAM_B_BY_9, 9)
    gs1 = gameplay.Game_score.from_position(board, komi=6.5)
    tc.assertEqual(gs1.winner, 'b')
    tc.assertEqual(gs1.margin, 9-6.5)
    tc.assertIsNone(gs1.get_detail())
    gs2 = gameplay.Game_score.from_position(
        board, komi=0,
        handicap_compensation='full', handicap=9)
    tc.assertEqual(gs2.winner, None)
    tc.assertEqual(gs2.margin, 0)
    tc.assertIsNone(gs2.get_detail())
Esempio n. 4
0
def test_game_score_from_position(tc):
    board = ascii_boards.interpret_diagram(DIAGRAM_B_BY_9, 9)
    gs1 = gameplay.Game_score.from_position(board, komi=6.5)
    tc.assertEqual(gs1.winner, 'b')
    tc.assertEqual(gs1.margin, 9 - 6.5)
    tc.assertIsNone(gs1.get_detail())
    gs2 = gameplay.Game_score.from_position(board,
                                            komi=0,
                                            handicap_compensation='full',
                                            handicap=9)
    tc.assertEqual(gs2.winner, None)
    tc.assertEqual(gs2.margin, 0)
    tc.assertIsNone(gs2.get_detail())
Esempio n. 5
0
def test_interpret_diagram(tc):
    b1 = boards.Board(9)
    b1.play(2, 3, 'b')
    b1.play(3, 4, 'w')
    b2 = ascii_boards.interpret_diagram(_9x9_expected, 9)
    tc.assertEqual(b1, b2)
    b3 = boards.Board(9)
    b4 = ascii_boards.interpret_diagram(_9x9_expected, 9, b3)
    tc.assertIs(b3, b4)
    tc.assertEqual(b1, b3)
    tc.assertRaisesRegexp(ValueError, "board not empty",
                          ascii_boards.interpret_diagram, _9x9_expected, 9, b3)
    b5 = boards.Board(19)
    tc.assertRaisesRegexp(ValueError, "wrong board size, must be 9$",
                          ascii_boards.interpret_diagram, _9x9_expected, 9, b5)

    tc.assertRaises(ValueError, ascii_boards.interpret_diagram, "nonsense", 9)
    b6 = ascii_boards.interpret_diagram(_13x13_expected, 13)
    tc.assertDiagramEqual(ascii_boards.render_board(b6), _13x13_expected)

    padded = "\n\n" + _9x9_expected + "\n\n"
    tc.assertEqual(b1, ascii_boards.interpret_diagram(padded, 9))
Esempio n. 6
0
 def runTest(self):
     b = ascii_boards.interpret_diagram(self.diagram, 9)
     self.assertEqual(b.area_score(), self.score, "wrong score")
Esempio n. 7
0
 def coerce(board, diagram):
     try:
         return board, ascii_boards.interpret_diagram(diagram, board.side)
     except ValueError:
         return ascii_boards.render_board(board), diagram
Esempio n. 8
0
 def runTest(self):
     b = ascii_boards.interpret_diagram(self.diagram, 9)
     self.assertEqual(b.area_score(), self.score, "wrong score")