示例#1
0
 def test_get_out_of_bound(self):
     table = chess.Table(5, 5)
     self.assertEquals(chess.Table.EMPTY, table.get(0, 0))
     self.assertEquals(chess.Table.EMPTY, table.get(4, 4))
     self.assertEquals(None, table.get(4, 5))
     self.assertEquals(None, table.get(5, 1))
     self.assertEquals(None, table.get(-1, -1))
示例#2
0
 def test_column_wise_is_finished(self):
     table = chess.Table(10, 10)
     self.assertTrue(table.set(1, 5, chess.Table.BLACK))
     self.assertTrue(table.set(2, 5, chess.Table.BLACK))
     self.assertTrue(table.set(3, 5, chess.Table.BLACK))
     self.assertTrue(table.set(4, 5, chess.Table.BLACK))
     self.assertTrue(table.set(5, 5, chess.Table.BLACK))
     self.assertTrue(table.is_finished())
示例#3
0
 def test_row_wise_is_finished(self):
     table = chess.Table(10, 10)
     self.assertTrue(table.set(0, 1, chess.Table.BLACK))
     self.assertTrue(table.set(0, 2, chess.Table.BLACK))
     self.assertTrue(table.set(0, 3, chess.Table.BLACK))
     self.assertTrue(table.set(0, 4, chess.Table.BLACK))
     self.assertTrue(table.set(0, 5, chess.Table.BLACK))
     self.assertTrue(table.is_finished())
示例#4
0
    def test_lower_left_to_upper_right_is_finished(self):
        # upper left
        table = chess.Table(10, 6)
        self.assertTrue(table.set(4, 0, chess.Table.WHITE))
        self.assertTrue(table.set(3, 1, chess.Table.WHITE))
        self.assertTrue(table.set(2, 2, chess.Table.WHITE))
        self.assertTrue(table.set(1, 3, chess.Table.WHITE))
        self.assertTrue(table.set(0, 4, chess.Table.WHITE))
        self.assertTrue(table.is_finished())

        # lower right
        table = chess.Table(10, 6)
        self.assertTrue(table.set(9, 1, chess.Table.WHITE))
        self.assertTrue(table.set(8, 2, chess.Table.WHITE))
        self.assertTrue(table.set(7, 3, chess.Table.WHITE))
        self.assertTrue(table.set(6, 4, chess.Table.WHITE))
        self.assertTrue(table.set(5, 5, chess.Table.WHITE))
        self.assertTrue(table.is_finished())
示例#5
0
    def test_set_value(self):
        table = chess.Table(5, 5)
        self.assertTrue(table.set(0, 0, chess.Table.WHITE))
        self.assertFalse(table.set(0, 0, chess.Table.BLACK))
        self.assertEquals(chess.Table.WHITE, table.get(0, 0))

        self.assertEquals(chess.Table.EMPTY, table.get(0, 1))

        self.assertTrue(table.set(0, 1, chess.Table.BLACK))
        self.assertFalse(table.set(0, 1, chess.Table.WHITE))
        self.assertEquals(chess.Table.BLACK, table.get(0, 1))

        self.assertFalse(table.set(0, 2, chess.Table.EMPTY))
        self.assertEquals(chess.Table.EMPTY, table.get(0, 2))
示例#6
0
    def test_different_type_in_middle_is_unfinished(self):
        table = chess.Table(10, 6)
        self.assertTrue(table.set(0, 1, chess.Table.WHITE))
        self.assertTrue(table.set(1, 2, chess.Table.WHITE))
        self.assertTrue(table.set(2, 3, chess.Table.BLACK))
        self.assertTrue(table.set(3, 4, chess.Table.WHITE))
        self.assertTrue(table.set(4, 5, chess.Table.WHITE))
        self.assertFalse(table.is_finished())

        table = chess.Table(10, 6)
        self.assertTrue(table.set(1, 0, chess.Table.WHITE))
        self.assertTrue(table.set(2, 1, chess.Table.WHITE))
        self.assertTrue(table.set(3, 2, chess.Table.BLACK))
        self.assertTrue(table.set(4, 3, chess.Table.WHITE))
        self.assertTrue(table.set(5, 4, chess.Table.WHITE))
        self.assertFalse(table.is_finished())

        table = chess.Table(10, 6)
        self.assertTrue(table.set(4, 0, chess.Table.WHITE))
        self.assertTrue(table.set(3, 1, chess.Table.WHITE))
        self.assertTrue(table.set(2, 2, chess.Table.WHITE))
        self.assertTrue(table.set(1, 3, chess.Table.WHITE))
        self.assertTrue(table.set(0, 4, chess.Table.BLACK))
        self.assertFalse(table.is_finished())

        table = chess.Table(10, 6)
        self.assertTrue(table.set(9, 1, chess.Table.BLACK))
        self.assertTrue(table.set(8, 2, chess.Table.WHITE))
        self.assertTrue(table.set(7, 3, chess.Table.WHITE))
        self.assertTrue(table.set(6, 4, chess.Table.WHITE))
        self.assertTrue(table.set(5, 5, chess.Table.WHITE))
        self.assertFalse(table.is_finished())

        table = chess.Table(10, 10)
        self.assertTrue(table.set(0, 1, chess.Table.BLACK))
        self.assertTrue(table.set(0, 2, chess.Table.WHITE))
        self.assertTrue(table.set(0, 3, chess.Table.BLACK))
        self.assertTrue(table.set(0, 4, chess.Table.BLACK))
        self.assertTrue(table.set(0, 5, chess.Table.BLACK))
        self.assertFalse(table.is_finished())

        table = chess.Table(10, 10)
        self.assertTrue(table.set(1, 5, chess.Table.BLACK))
        self.assertTrue(table.set(2, 5, chess.Table.BLACK))
        self.assertTrue(table.set(3, 5, chess.Table.BLACK))
        self.assertTrue(table.set(4, 5, chess.Table.WHITE))
        self.assertTrue(table.set(5, 5, chess.Table.BLACK))
        self.assertFalse(table.is_finished())
示例#7
0
文件: cli.py 项目: xudifsd/izzy
def replay_session(src):
    """ replay alread saved sessions """
    for data in persist.iterate_over_store(SAVE_TARGET):
        session = chess.Session.deserialize(data)

        # for display
        table = chess.Table(chess.Session.TABLE_SIZE, chess.Session.TABLE_SIZE)

        types = [chess.Table.BLACK, chess.Table.WHITE]
        i = 0

        for move in session.history:
            table.set(move.row, move.col, types[i])
            i += 1
            i %= 2

            date = datetime.datetime.fromtimestamp(move.timestamp)

            print "%s(is_ai=%r) make move in %d,%d in %s" % (
                move.author, move.is_ai, move.row, move.col, date.isoformat())
            print table.to_ascii()
            time.sleep(0.3)

        print "-" * 100