Exemplo n.º 1
0
 def test_parse_drop(self):
     shogi = create_shogi()
     shogi.board[6][0] = Koma.empty
     shogi._shogi.first_tegoma = [Koma.fu]
     shogi._shogi.first = True
     self.assertEqual(ParseInput.parse("95歩打", shogi),
                      (-1, -1, 0, 4, False, Koma.fu))
     self.assertEqual(ParseInput.parse("95歩打成", shogi), False)
Exemplo n.º 2
0
 def test_parse_drop(self):
     shogi = create_shogi()
     shogi.board[6][0] = Koma.empty
     shogi._shogi.first_tegoma = [Koma.fu]
     shogi._shogi.first = True
     self.assertEqual(ParseInput.parse("95歩打", shogi),
                      (-1, -1, 0, 4, False, Koma.fu))
     self.assertEqual(ParseInput.parse("95歩打成", shogi), False)
Exemplo n.º 3
0
    def test_parse_same(self):
        shogi = create_shogi()
        shogi.move(2, 6, 2, 5, False)  # 76歩
        shogi.move(2, 2, 2, 3, False)  # 74歩
        shogi.move(2, 5, 2, 4, False)  # 75歩
        self.assertEqual(ParseInput.parse("同歩", shogi),
                         (2, 3, 2, 4, False, Koma.opponent_fu))

        shogi = create_shogi()
        shogi.move(5, 8, 4, 1, False)  # 49の金を一気に52へ
        self.assertEqual(ParseInput.parse("同金右", shogi),
                         (3, 0, 4, 1, False, Koma.opponent_kin))
Exemplo n.º 4
0
    def test_parse_same(self):
        shogi = create_shogi()
        shogi.move(2, 6, 2, 5, False)  # 76歩
        shogi.move(2, 2, 2, 3, False)  # 74歩
        shogi.move(2, 5, 2, 4, False)  # 75歩
        self.assertEqual(ParseInput.parse("同歩", shogi),
                         (2, 3, 2, 4, False, Koma.opponent_fu))

        shogi = create_shogi()
        shogi.move(5, 8, 4, 1, False)  # 49の金を一気に52へ
        self.assertEqual(ParseInput.parse("同金右", shogi),
                         (3, 0, 4, 1, False, Koma.opponent_kin))
Exemplo n.º 5
0
 def test_parse_sugu(self):
     shogi = create_shogi()
     shogi.move(5, 8, 4, 7, False) # 58金
     shogi.move(0, 2, 0, 3, False) # 94歩
     shogi.move(3, 6, 3, 5, False) # 66歩
     shogi.move(0, 3, 0, 4, False) # 95歩
     shogi.move(4, 7, 3, 6, False) # 67金
     shogi.move(0, 4, 0, 5, False) # 96歩
     self.assertEqual(ParseInput.parse("68金直", shogi),
                      (3, 8, 3, 7, False, Koma.kin))
Exemplo n.º 6
0
 def test_parse_sugu(self):
     shogi = create_shogi()
     shogi.move(5, 8, 4, 7, False)  # 58金
     shogi.move(0, 2, 0, 3, False)  # 94歩
     shogi.move(3, 6, 3, 5, False)  # 66歩
     shogi.move(0, 3, 0, 4, False)  # 95歩
     shogi.move(4, 7, 3, 6, False)  # 67金
     shogi.move(0, 4, 0, 5, False)  # 96歩
     self.assertEqual(ParseInput.parse("68金直", shogi),
                      (3, 8, 3, 7, False, Koma.kin))
Exemplo n.º 7
0
 def test_parse2(self):
     shogi = create_shogi()
     self.assertEqual(ParseInput.parse("58金右", shogi),
                      (5, 8, 4, 7, False, Koma.kin))
     self.assertEqual(ParseInput.parse("58金左", shogi),
                      (3, 8, 4, 7, False, Koma.kin))
     self.assertEqual(ParseInput.parse("58金直", shogi), False)
     self.assertEqual(ParseInput.parse("58金寄", shogi), False)
     self.assertEqual(ParseInput.parse("58金引", shogi), False)
     shogi.move(4, 8, 5, 7, False)
     shogi.move(5, 8, 4, 8, False)
     shogi._shogi.first = True
     self.assertIn([3, 8], shogi.find_koma(Koma.kin))
     self.assertIn([4, 8], shogi.find_koma(Koma.kin))
     self.assertEqual(ParseInput.parse("58金直", shogi),
                      (4, 8, 4, 7, False, Koma.kin))
     self.assertEqual(ParseInput.parse("58金左", shogi),
                      (3, 8, 4, 7, False, Koma.kin))
     self.assertEqual(ParseInput.parse("58金右", shogi), False)
     self.assertEqual(ParseInput.parse("58金寄", shogi), False)
     self.assertEqual(ParseInput.parse("58金引", shogi), False)
Exemplo n.º 8
0
 def test_parse2(self):
     shogi = create_shogi()
     self.assertEqual(ParseInput.parse("58金右", shogi),
                      (5, 8, 4, 7, False, Koma.kin))
     self.assertEqual(ParseInput.parse("58金左", shogi),
                      (3, 8, 4, 7, False, Koma.kin))
     self.assertEqual(ParseInput.parse("58金直", shogi), False)
     self.assertEqual(ParseInput.parse("58金寄", shogi), False)
     self.assertEqual(ParseInput.parse("58金引", shogi), False)
     shogi.move(4, 8, 5, 7, False)
     shogi.move(5, 8, 4, 8, False)
     shogi._shogi.first = True
     self.assertIn([3, 8], shogi.find_koma(Koma.kin))
     self.assertIn([4, 8], shogi.find_koma(Koma.kin))
     self.assertEqual(ParseInput.parse("58金直", shogi),
                      (4, 8, 4, 7, False, Koma.kin))
     self.assertEqual(ParseInput.parse("58金左", shogi),
                      (3, 8, 4, 7, False, Koma.kin))
     self.assertEqual(ParseInput.parse("58金右", shogi), False)
     self.assertEqual(ParseInput.parse("58金寄", shogi), False)
     self.assertEqual(ParseInput.parse("58金引", shogi), False)
Exemplo n.º 9
0
    def test_parse1(self):
        shogi = create_shogi()
        self.assertEqual(ParseInput.parse("76歩", shogi),
                         (2, 6, 2, 5, False, Koma.fu))
        self.assertEqual(ParseInput.parse("7六歩", shogi),
                         (2, 6, 2, 5, False, Koma.fu))
        self.assertEqual(ParseInput.parse("75歩", shogi), False)
        self.assertEqual(ParseInput.parse("34歩", shogi), False)

        shogi.move(2, 6, 2, 5, False)
        self.assertEqual(ParseInput.parse("34歩", shogi),
                         (6, 2, 6, 3, False, Koma.opponent_fu))
        self.assertEqual(ParseInput.parse("35歩", shogi), False)
        self.assertEqual(ParseInput.parse("75歩", shogi), False)
Exemplo n.º 10
0
    def test_parse1(self):
        shogi = create_shogi()
        self.assertEqual(ParseInput.parse("76歩", shogi),
                         (2, 6, 2, 5, False, Koma.fu))
        self.assertEqual(ParseInput.parse("7六歩", shogi),
                         (2, 6, 2, 5, False, Koma.fu))
        self.assertEqual(ParseInput.parse("75歩", shogi), False)
        self.assertEqual(ParseInput.parse("34歩", shogi), False)

        shogi.move(2, 6, 2, 5, False)
        self.assertEqual(ParseInput.parse("34歩", shogi),
                         (6, 2, 6, 3, False, Koma.opponent_fu))
        self.assertEqual(ParseInput.parse("35歩", shogi), False)
        self.assertEqual(ParseInput.parse("75歩", shogi), False)
Exemplo n.º 11
0
    def move(movement_str, channel_id, user_id):
        shogi = ShogiInput.manager.get_shogi(channel_id)
        if not shogi.validate(shogi, user_id):
            raise UserDifferentException()

        movement = ParseInput.parse(movement_str, shogi)
        if not movement:
            raise KomaCannotMoveException()

        from_x, from_y, to_x, to_y, promote, koma = movement

        if from_x == -1 and from_y == -1 and shogi.droppable(koma, to_x, to_y):
            shogi.drop(koma, to_x, to_y)
        elif shogi.movable(from_x, from_y, to_x, to_y, promote):
            shogi.move(from_x, from_y, to_x, to_y, promote)
        else:
            raise KomaCannotMoveException()
Exemplo n.º 12
0
    def move(movement_str, channel_id, user_id):
        shogi = ShogiInput.manager.get_shogi(channel_id)
        if not shogi.validate(shogi, user_id):
            raise UserDifferentException()

        movement = ParseInput.parse(movement_str, shogi)
        if not movement:
            raise KomaCannotMoveException()

        from_x, from_y, to_x, to_y, promote, koma = movement

        if from_x == -1 and from_y == -1 and shogi.droppable(koma, to_x, to_y):
            shogi.drop(koma, to_x, to_y)
        elif shogi.movable(from_x, from_y, to_x, to_y, promote):
            shogi.move(from_x, from_y, to_x, to_y, promote)
        else:
            raise KomaCannotMoveException()
Exemplo n.º 13
0
    def test_parse3(self):
        shogi = create_shogi()
        shogi.move(2, 6, 2, 5, False)  # 76歩
        shogi.move(6, 2, 6, 3, False)  # 34歩
        self.assertEqual(ParseInput.parse("22角成", shogi),
                         (1, 7, 7, 1, True, Koma.kaku))
        self.assertEqual(ParseInput.parse("22角不成", shogi),
                         (1, 7, 7, 1, False, Koma.kaku))
        self.assertEqual(ParseInput.parse("22角", shogi),
                         (1, 7, 7, 1, False, Koma.kaku))
        self.assertEqual(ParseInput.parse("11角成", shogi), False)

        shogi.move(1, 7, 7, 1, True)
        self.assertEqual(ParseInput.parse("22同銀", shogi),
                         (6, 0, 7, 1, False, Koma.opponent_gin))
        self.assertEqual(ParseInput.parse("22銀", shogi),
                         (6, 0, 7, 1, False, Koma.opponent_gin))
        self.assertEqual(ParseInput.parse("22銀成", shogi), False)
Exemplo n.º 14
0
    def test_parse3(self):
        shogi = create_shogi()
        shogi.move(2, 6, 2, 5, False)  # 76歩
        shogi.move(6, 2, 6, 3, False)  # 34歩
        self.assertEqual(ParseInput.parse("22角成", shogi),
                         (1, 7, 7, 1, True, Koma.kaku))
        self.assertEqual(ParseInput.parse("22角不成", shogi),
                         (1, 7, 7, 1, False, Koma.kaku))
        self.assertEqual(ParseInput.parse("22角", shogi),
                         (1, 7, 7, 1, False, Koma.kaku))
        self.assertEqual(ParseInput.parse("11角成", shogi), False)

        shogi.move(1, 7, 7, 1, True)
        self.assertEqual(ParseInput.parse("22同銀", shogi),
                         (6, 0, 7, 1, False, Koma.opponent_gin))
        self.assertEqual(ParseInput.parse("22銀", shogi),
                         (6, 0, 7, 1, False, Koma.opponent_gin))
        self.assertEqual(ParseInput.parse("22銀成", shogi), False)
Exemplo n.º 15
0
 def test_parse_ambiguous(self):
     shogi = create_shogi()
     self.assertEqual(ParseInput.parse("58金", shogi), False)
Exemplo n.º 16
0
 def test_parse_ambiguous(self):
     shogi = create_shogi()
     self.assertEqual(ParseInput.parse("58金", shogi), False)