コード例 #1
0
def play_game(players, verbose=False):
    field = Field()
    for turn in range(9):
        id_player = turn % 2
        move = players[id_player].move(field.field)
        field.field[0, move] = 1
        status = field.eval()

        if id_player == 1:
            status = -status

        s = field.to_str(id_player)
        if verbose:
            print(s)

        if status[0] > 0:
            if verbose:
                print("Victory of x!")
            return 1
        if status[0] < 0:
            if verbose:
                print("victory of o!")
            return -1
        field.field = -field.field
    return 0
コード例 #2
0
 def test_search_free_turn_cell(self):  # Проверка поиска (2 белые шашки)
     field = Field(4, "RU")
     field.field = \
         [[0, 0, 0, 0],
          [0, 0, 0, 0],
          [0, 1, 0, 0],
          [0, 0, 0, 1]]
     answer_list = [((1, 2), (0, 1)), ((1, 2), (2, 1)), ((3, 3), (2, 2))]
     self.assertEqual(Window.search_free_turn([], True, field), answer_list)
コード例 #3
0
 def test_must_turn_king2(self):
     field = Field(4, "RU")
     field.field = \
         [[0, 0, 0, 0],
          [3, 0, 0, 0],
          [0, 2, 0, 0],
          [0, 0, 0, 0]]
     answer_list = [((0, 1), (2, 3))]
     self.assertEqual(Window.must_turn_king([], 0, 1, True, field),
                      answer_list)
コード例 #4
0
 def test_must_turn_cell2(self):
     field = Field(4, "RU")
     field.field = \
            [[0, 0, 0, 0],
             [0, 2, 0, 0],
             [0, 0, 1, 0],
             [0, 0, 0, 0]]
     answer_list = [((2, 2), (0, 0))]
     self.assertEqual(Window.must_turn_cell([], 2, 2, True, field),
                      answer_list)
コード例 #5
0
    def test_free_turn_king2_extra1(self):
        field = Field(2, "RU")

        field.field = \
            [[0, 3],
             [0, 0]]

        answer_list = [((1, 0), (0, 1))]
        self.assertEqual(Window.free_turn_king([], 1, 0, True, field),
                         answer_list)
コード例 #6
0
    def test_free_turn_cell2(self):  # Проверка черной шашки 2 хода назад
        field = Field(3, "RU")
        field.field = \
            [[0, 2, 0],
             [0, 0, 0],
             [0, 0, 0]]

        answer_list = [((1, 0), (2, 1)), ((1, 0), (0, 1))]
        self.assertEqual(Window.free_turn_cell([], 1, 0, False, field),
                         answer_list)
コード例 #7
0
    def test_free_turn_king2(self):
        field = Field(3, "RU")
        field.field = \
            [[0, 0, 0],
             [0, 0, 0],
             [0, 3, 0]]

        answer_list = [((1, 2), (0, 1)), ((1, 2), (2, 1))]
        self.assertEqual(Window.free_turn_king([], 1, 2, True, field),
                         answer_list)
コード例 #8
0
 def test_must_turn_king6(self):
     field = Field(4, "RU")
     field.field = \
         [[0, 0, 0, 0],
          [4, 0, 0, 0],
          [0, 0, 0, 0],
          [0, 0, 1, 0]]
     answer_list = []
     self.assertEqual(Window.must_turn_king([], 0, 1, False, field),
                      answer_list)
コード例 #9
0
    def test_free_turn_cell5(self):  # Проверка белой шашки 2 хода вперёд
        field = Field(3, "RU")
        field.field = \
            [[0, 0, 0],
             [0, 0, 0],
             [0, 1, 0]]

        answer_list = [((1, 2), (0, 1)), ((1, 2), (2, 1))]
        self.assertEqual(Window.free_turn_cell([], 1, 2, True, field),
                         answer_list)
コード例 #10
0
 def test_must_turn_cell16(self):
     field = Field(4, "RU")
     field.field = \
            [[0, 0, 0, 0],
             [0, 0, 0, 2],
             [0, 0, 1, 0],
             [0, 0, 0, ]]
     answer_list = [((3, 1), (1, 3))]
     self.assertEqual(Window.must_turn_cell([], 3, 1, False, field),
                      answer_list)
コード例 #11
0
 def test_free_turn_cell3(self):
     field = Field(4, "RU")
     field.field = \
         [[0, 0, 0, 0],
          [0, 0, 1, 0],
          [0, 0, 0, 0],
          [0, 0, 0, 0]]
     answer_list = [((2, 1), (1, 0)), ((2, 1), (3, 0))]
     self.assertEqual(Window.free_turn_cell([], 2, 1, True, field),
                      answer_list)
コード例 #12
0
 def test_must_turn_king5(self):
     field = Field(4, "RU")
     field.field = \
         [[0, 0, 0, 4],
          [0, 0, 0, 0],
          [0, 1, 0, 0],
          [0, 0, 0, 0]]
     answer_list = [((3, 0), (0, 3))]
     self.assertEqual(Window.must_turn_king([], 3, 0, False, field),
                      answer_list)
コード例 #13
0
 def test_must_turn_cell15(self):
     field = Field(4, "RU")
     field.field = \
            [[0, 0, 0, 0],
             [0, 0, 0, 0],
             [0, 2, 0, 0],
             [1, 0, 0, ]]
     answer_list = [((0, 3), (2, 1))]
     self.assertEqual(Window.must_turn_cell([], 0, 3, True, field),
                      answer_list)
コード例 #14
0
 def test_must_turn_cell9(self):
     field = Field(4, "RU")
     field.field = \
            [[0, 0, 0, 0],
             [0, 0, 0, 0],
             [0, 0, 4, 0],
             [0, 0, 0, 1]]
     answer_list = [((3, 3), (1, 1))]
     self.assertEqual(Window.must_turn_cell([], 3, 3, True, field),
                      answer_list)
コード例 #15
0
 def test_must_turn_cell10(self):
     field = Field(4, "RU")
     field.field = \
         [[2, 0, 0, 0],
          [0, 3, 0, 0],
          [0, 0, 0, 0],
          [0, 0, 0, 0]]
     answer_list = [((0, 0), (2, 2))]
     self.assertEqual(Window.must_turn_cell([], 0, 0, False, field),
                      answer_list)
コード例 #16
0
    def test_free_turn_king1_extra3(self):
        field = Field(2, "RU")

        field.field = \
            [[0, 0],
             [4, 0]]

        answer_list = [((0, 1), (1, 0))]
        self.assertEqual(Window.free_turn_king([], 0, 1, False, field),
                         answer_list)
コード例 #17
0
    def test_free_turn_cell10(
            self):  # Проверка черной шашки 1 ход назад у правой стены
        field = Field(4, "RU")

        field.field = \
            [[0, 0, 0, 0],
             [0, 0, 0, 2],
             [0, 0, 0, 0],
             [0, 0, 0, 0]]
        answer_list = [((3, 1), (2, 2))]
        self.assertEqual(Window.free_turn_cell([], 3, 1, False, field),
                         answer_list)
コード例 #18
0
 def test_must_turn_cell120(self):
     field = Field(6, "RU")
     field.field = \
         [[0, 1, 0, 0, 0, 1],
          [0, 0, 2, 0, 2, 0],
          [0, 0, 0, 1, 0, 0],
          [0, 0, 2, 0, 2, 0],
          [0, 1, 0, 0, 0, 1],
          [0, 0, 0, 0, 0, 0]]
     answer_list = []
     self.assertEqual(Window.must_turn_cell([], 3, 2, True, field),
                      answer_list)
コード例 #19
0
    def test_free_turn_cell12(
            self):  # Проверка черной шашки 0 ход назад у левой стены
        field = Field(4, "RU")

        field.field = \
            [[0, 0, 0, 0],
             [0, 0, 0, 0],
             [2, 0, 0, 0],
             [0, 2, 0, 0]]
        answer_list = []
        self.assertEqual(Window.free_turn_cell([], 0, 2, False, field),
                         answer_list)
コード例 #20
0
    def test_free_turn_king9(self):
        field = Field(4, "RU")

        field.field = \
            [[0, 0, 0, 0],
             [0, 0, 2, 0],
             [0, 4, 0, 0],
             [0, 0, 0, 0]]

        answer_list = [((1, 2), (0, 1)), ((1, 2), (0, 3)), ((1, 2), (2, 3))]
        self.assertEqual(Window.free_turn_king([], 1, 2, False, field),
                         answer_list)
コード例 #21
0
    def test_free_turn_king7(self):
        field = Field(4, "RU")

        field.field = \
            [[0, 1, 0, 0],
             [3, 0, 0, 0],
             [0, 1, 0, 0],
             [0, 0, 0, 0]]

        answer_list = []
        self.assertEqual(Window.free_turn_king([], 0, 1, True, field),
                         answer_list)
コード例 #22
0
    def test_free_turn_king5(self):
        field = Field(4, "RU")

        field.field = \
            [[0, 0, 0, 0],
             [3, 0, 0, 0],
             [0, 0, 0, 0],
             [0, 0, 0, 0]]

        answer_list = [((0, 1), (1, 0)), ((0, 1), (1, 2)), ((0, 1), (2, 3))]
        self.assertEqual(Window.free_turn_king([], 0, 1, True, field),
                         answer_list)
コード例 #23
0
    def test_free_turn_king10(self):
        field = Field(4, "RU")

        field.field = \
            [[0, 0, 0, 0],
             [2, 0, 2, 0],
             [0, 4, 0, 0],
             [2, 0, 2, 0]]

        answer_list = []
        self.assertEqual(Window.free_turn_king([], 1, 2, False, field),
                         answer_list)
コード例 #24
0
    def test_free_turn_cell13(
            self):  # Проверка белой шашки 0 ход вперёд у левой стены
        field = Field(4, "RU")

        field.field = \
            [[0, 0, 0, 0],
             [0, 1, 0, 0],
             [1, 0, 0, 0],
             [0, 0, 0, 0]]
        answer_list = []
        self.assertEqual(Window.free_turn_cell([], 0, 2, True, field),
                         answer_list)
コード例 #25
0
    def test_free_turn_cell7(
            self):  # Проверка белой шашки 1 ход вперёд у правой стены
        field = Field(4, "RU")

        field.field = \
            [[0, 0, 0, 0],
             [0, 0, 0, 0],
             [0, 0, 0, 0],
             [0, 0, 0, 1]]
        answer_list = [((3, 3), (2, 2))]
        self.assertEqual(Window.free_turn_cell([], 3, 3, True, field),
                         answer_list)
コード例 #26
0
 def test_must_turn_king8(self):
     field = Field(6, "RU")
     field.field = \
         [[0, 4, 0, 0, 0, 0],
          [0, 0, 0, 0, 0, 0],
          [0, 0, 0, 0, 0, 0],
          [0, 0, 0, 0, 1, 0],
          [0, 0, 0, 0, 0, 0],
          [0, 0, 0, 0, 0, 0]]
     answer_list = [((1, 0), (5, 4))]
     self.assertEqual(Window.must_turn_king([], 1, 0, False, field),
                      answer_list)
コード例 #27
0
def multiply(background: Field, foreground: Field):
    white = Field(10, 20)
    for x in range(10):
        for y in range(20):
            white.set_pixel(x, y, [255, 255, 255])

    bg = numpy.array(background.field)
    fg = numpy.array(foreground.field)
    multi = numpy.multiply(bg, fg)
    multi = numpy.divide(multi, white.field)
    combined = Field(10, 20)
    combined.field = multi.astype(int).tolist()
    return combined
コード例 #28
0
    def test_free_turn_cell6(
            self):  # Проверка чёрной шашки два хода назад (не вперёд)
        field = Field(4, "RU")

        field.field = \
        [[0, 0, 0, 0],
         [0, 0, 0, 0],
         [0, 2, 0, 0],
         [0, 0, 0, 0]]

        answer_list = [((1, 2), (2, 3)), ((1, 2), (0, 3))]
        self.assertEqual(Window.free_turn_cell([], 1, 2, False, field),
                         answer_list)
コード例 #29
0
 def test_must_turn_cell13(self):
     field = Field(6, "RU")
     field.field = \
         [[0, 0, 0, 0, 0, 0],
          [0, 0, 4, 0, 4, 0],
          [0, 0, 0, 1, 0, 0],
          [0, 0, 4, 0, 4, 0],
          [0, 0, 0, 0, 0, 0],
          [0, 0, 0, 0, 0, 0]]
     answer_list = [((3, 2), (1, 0)), ((3, 2), (1, 4)), ((3, 2), (5, 0)),
                    ((3, 2), (5, 4))]
     self.assertEqual(Window.must_turn_cell([], 3, 2, True, field),
                      answer_list)
コード例 #30
0
    def test_free_turn_king12(self):
        field = Field(6, "RU")

        field.field = \
            [[0, 0, 0, 0, 0, 0],
             [0, 1, 0, 0, 0, 0],
             [0, 0, 0, 0, 1, 0],
             [0, 0, 0, 3, 0, 0],
             [0, 0, 1, 0, 0, 0],
             [0, 0, 0, 0, 0, 1]]

        answer_list = [((3, 3), (2, 2)), ((3, 3), (4, 4))]
        self.assertEqual(Window.free_turn_king([], 3, 3, True, field),
                         answer_list)