Exemple #1
0
 def test_simple_attack(self):
     g = Game()
     board = [
         list(' b b b b b'),
         list('b b b b b '),
         list(' b b b b b'),
         list('b b . b b '),
         list(' . . . . .'),
         list('. . b . . '),
         list(' w w w w w'),
         list('w w w w w '),
         list(' w w w w w'),
         list('w w w w w ')
     ]
     newboard = g.get_board_after_move(board, [(6, 3), (5, 4), (4, 5)])
     validboard = [
         list(' b b b b b'),
         list('b b b b b '),
         list(' b b b b b'),
         list('b b . b b '),
         list(' . . w . .'),
         list('. . . . . '),
         list(' w . w w w'),
         list('w w w w w '),
         list(' w w w w w'),
         list('w w w w w ')
     ]
     self.assertEqual(newboard, validboard)
Exemple #2
0
 def test_kings_becoming(self):
     g = Game()
     g.board = [
         list(' . . . . .'),  # 0
         list('. w . . . '),  # 1
         list(' . . . . .'),  # 2
         list('. . . . . '),  # 3
         list(' . . . . .'),  # 4
         list('. . . . . '),  # 5
         list(' . . . . .'),  # 6
         list('. . . . . '),  # 7
         list(' b . . . .'),  # 8
         list('. . . . . ')   # 9
     ]
     self.assertTrue(g.makemove([(1, 2), (0, 1)]))    # valid
     self.assertTrue(g.makemove([(8, 1), (9, 0)]))    # valid
     validboard = [
         list(' W . . . .'),  # 0
         list('. . . . . '),  # 1
         list(' . . . . .'),  # 2
         list('. . . . . '),  # 3
         list(' . . . . .'),  # 4
         list('. . . . . '),  # 5
         list(' . . . . .'),  # 6
         list('. . . . . '),  # 7
         list(' . . . . .'),  # 8
         list('B . . . . ')   # 9
     ]
     self.assertEqual(g.board, validboard)
Exemple #3
0
 def test_simple_move(self):
     g = Game()
     board = [
         list(' b b b b b'),
         list('b b b b b '),
         list(' b b b b b'),
         list('b b b b b '),
         list(' . . . . .'),
         list('. . . . . '),
         list(' w w w w w'),
         list('w w w w w '),
         list(' w w w w w'),
         list('w w w w w ')
     ]
     newboard = g.get_board_after_move(board, [(6, 1), (5, 2)])
     validboard = [
         list(' b b b b b'),
         list('b b b b b '),
         list(' b b b b b'),
         list('b b b b b '),
         list(' . . . . .'),
         list('. w . . . '),
         list(' . w w w w'),
         list('w w w w w '),
         list(' w w w w w'),
         list('w w w w w ')
     ]
     self.assertEqual(newboard, validboard)
Exemple #4
0
 def test_king_multi_capture(self):
     g = Game()
     g.board = [
         list(' . . . . .'),  # 0
         list('. . . . . '),  # 1
         list(' . . . b .'),  # 2
         list('. . . . . '),  # 3
         list(' . . b . .'),  # 4
         list('. . . . . '),  # 5
         list(' . W . . .'),  # 6
         list('. . b b . '),  # 7
         list(' b . . . .'),  # 8
         list('b . . b b ')   # 9
     ]
     moves = g.get_possible_moves()
     valid_moves = [
         [(6, 3), (7, 4), (8, 5), (7, 6), (6, 7), (4, 5), (3, 4)],
         [(6, 3), (7, 4), (8, 5), (7, 6), (6, 7), (4, 5), (2, 3)],
         [(6, 3), (7, 4), (8, 5), (7, 6), (6, 7), (4, 5), (1, 2)],
         [(6, 3), (7, 4), (8, 5), (7, 6), (6, 7), (4, 5), (0, 1)],
         [(6, 3), (7, 4), (8, 5), (7, 6), (4, 9), (2, 7), (1, 6)],
         [(6, 3), (7, 4), (8, 5), (7, 6), (4, 9), (2, 7), (0, 5)]]
     self.assertEqual(len(moves), len(valid_moves))
     for move in moves:
         self.assertTrue(move in valid_moves)
Exemple #5
0
def create_game_object(message):
    global sessions
    if sessions.get(message.chat.id) != 's':
        bot.send_message(message.chat.id, locale.wrong_command)
        return

    if message.text == locale.white:
        sessions[message.chat.id] = Game(enemy_white=True)
        reply = ''
    else:
        sessions[message.chat.id] = Game(enemy_white=False)
        moves_done = sessions[message.chat.id].black_first_move()
        reply = bot_reply(moves_done)

    picture = open('tmp.png', 'rb')
    bot.send_photo(message.chat.id,
                   picture,
                   '{}{}'.format(reply, locale.hi),
                   reply_markup=make_markup(sessions[message.chat.id], False))
Exemple #6
0
    def test_simple_capture(self):
        g = Game()
        g.board = [
            list(" b b b b b"),
            list('b b b b b '),
            list(' b b b b b'),
            list('b . b b b '),
            list(' . . . . .'),
            list('. b . . . '),
            list(' w w w w w'),
            list('w w w w w '),
            list(' w w w w w'),
            list('w w w w w ')
        ]
        moves = g.get_possible_moves()
        valid_moves = [[(6, 1), (5, 2), (4, 3)], [(6, 3), (5, 2), (4, 1)]]

        self.assertEqual(len(moves), len(valid_moves))
        for move in moves:
            self.assertTrue(move in valid_moves)
Exemple #7
0
    def test_multi_capture(self):
        g = Game()
        g.board = [
            list(' b b b b b'),  # 0
            list('b b b . b '),  # 1
            list(' b b b . .'),  # 2
            list('b . . b b '),  # 3
            list(' . b b . .'),  # 4
            list('. . . b . '),  # 5
            list(' b w w w w'),  # 6
            list('w w w w w '),  # 7
            list(' w w w w w'),  # 8
            list('w w w w w ')   # 9
        ]
        moves = g.get_possible_moves()
        valid_moves = [[(7, 0), (6, 1), (5, 2), (4, 3), (3, 4), (2, 5),
                        (1, 6)]]

        self.assertEqual(len(moves), len(valid_moves))
        for move in moves:
            self.assertTrue(move in valid_moves)
Exemple #8
0
    def test_more_advanced_capture(self):
        g = Game()
        g.board = [
            list(' . . b . b'),  # 0
            list('. b b b b '),  # 1
            list(' w b . . .'),  # 2
            list('. . . . . '),  # 3
            list(' . . . b .'),  # 4
            list('. . . . . '),  # 5
            list(' . . w w .'),  # 6
            list('w w . w w '),  # 7
            list(' w w w w w'),  # 8
            list('w w w w w ')   # 9
        ]
        moves = g.get_possible_moves()
        valid_moves = [[(2, 1), (1, 2), (0, 3), (1, 4),
            (2, 5), (1, 6), (0, 7), (1, 8), (2, 9)]]

        self.assertEqual(len(moves), len(valid_moves))
        for move in moves:
            self.assertTrue(move in valid_moves)
Exemple #9
0
 def test_king_moves(self):
     g = Game()
     g.board = [
         list(' . . . . .'),  # 0
         list('. . . . . '),  # 1
         list(' . . . . .'),  # 2
         list('. . . b . '),  # 3
         list(' . . b . .'),  # 4
         list('. . . . . '),  # 5
         list(' . W . . .'),  # 6
         list('. . . . . '),  # 7
         list(' b . . . .'),  # 8
         list('b . . b b ')   # 9
     ]
     moves = g.get_possible_moves()
     valid_moves = [
         [(6, 3), (7, 2)], [(6, 3), (5, 4)], [(6, 3), (5, 2)],
         [(6, 3), (4, 1)], [(6, 3), (3, 0)], [(6, 3), (7, 4)],
         [(6, 3), (8, 5)]]
     self.assertEqual(len(moves), len(valid_moves))
     for move in moves:
         self.assertTrue(move in valid_moves)
Exemple #10
0
    def test_advanced_capture(self):
        g = Game()
        g.board = [
            list(' b b b b b'),  # 0
            list('b b b b b '),  # 1
            list(' b b b . .'),  # 2
            list('b . . b b '),  # 3
            list(' . b . . .'),  # 4
            list('. . . b b '),  # 5
            list(' b b w w .'),  # 6
            list('w w . w w '),  # 7
            list(' w w w w w'),  # 8
            list('w w w w w ')   # 9
        ]
        moves = g.get_possible_moves()
        valid_moves = [[(6, 7), (5, 8), (4, 9), (3, 8),
            (2, 7), (3, 6), (4, 5), (5, 6), (6, 7)],
            [(6, 7), (5, 6), (4, 5), (3, 6), (2, 7),
             (3, 8), (4, 9), (5, 8), (6, 7)]]

        self.assertEqual(len(moves), len(valid_moves))
        for move in moves:
            self.assertTrue(move in valid_moves)
Exemple #11
0
    def test_init_possible_moves(self):
        g = Game()
        g.turn = "B"
        moves = g.get_possible_moves()
        valid_moves = [
            [(3, 0), (4, 1)], [(3, 2), (4, 1)], [(3, 2), (4, 3)],
            [(3, 4), (4, 3)], [(3, 4), (4, 5)], [(3, 6), (4, 5)],
            [(3, 6), (4, 7)], [(3, 8), (4, 7)], [(3, 8), (4, 9)]]

        self.assertEqual(len(moves), len(valid_moves))
        for move in moves:
            self.assertTrue(move in valid_moves)

        g = Game()
        g.turn = "W"
        moves = g.get_possible_moves()
        valid_moves = [
            [(6, 1), (5, 2)], [(6, 1), (5, 0)], [(6, 3), (5, 4)],
            [(6, 3), (5, 2)], [(6, 5), (5, 6)], [(6, 5), (5, 4)],
            [(6, 7), (5, 8)], [(6, 7), (5, 6)], [(6, 9), (5, 8)]]

        self.assertEqual(len(moves), len(valid_moves))
        for move in moves:
            self.assertTrue(move in valid_moves)
Exemple #12
0
    arm.move_j([move2, 1, 1])

    #logic for determining if move jumped a piece
    if (abs(move1 - move2) >= 14):
        val = (move2 - move1) / 2
        pickup = move1 + val
        #waits til human says to continue gameplay
        stop = input("tell when to go")

        #pickup and trash jumped piece
        arm.move_j([pickup, 0, 1])
        arm.move_j([pickup, 1, 0])


# initialize game object
game = Game.Game()
# set ip and port
arm = ArmController('192.168.125.1',
                    3000)  #'130.215.217.14',3000) #192.168.100.100
#attempt to connect
arm.connect()
game.consecutive_noncapture_move_limit = 50

while True:

    #human player turn
    if game.whose_turn() == 1:
        #breaks loop if game is over
        if game.is_over():
            break
        print("\nYour possible moves: ")
Exemple #13
0
def main():
    Game()
Exemple #14
0
    def test_few_moves(self):
        g = Game()
        g.board = [
            list(' b b b b b'),  # 0
            list('b b b b b '),  # 1
            list(' b b b b b'),  # 2
            list('b b b b b '),  # 3
            list(' . . . . .'),  # 4
            list('. . . . . '),  # 5
            list(' w w w w w'),  # 6
            list('w w w w w '),  # 7
            list(' w w w w w'),  # 8
            list('w w w w w ')   # 9
        ]

        self.assertFalse(g.makemove([(6, 2), (5, 0)]))  # impossible move
        self.assertTrue(g.makemove([(6, 1), (5, 0)]))   # valid move
        self.assertFalse(g.makemove([(6, 1), (5, 0)]))  # invalid, its
                                                        # opponent turn
        self.assertTrue(g.makemove([(3, 0), (4, 1)]))   # valid move
        self.assertTrue(g.makemove([(6, 3), (5, 2)]))   # valid move
        self.assertFalse(g.makemove([(2, 1), (3, 0)]))     # invalid, must kill
        self.assertTrue(g.makemove([(4, 1), (5, 2), (6, 3)]))    # killing
        self.assertTrue(g.makemove([(7, 2), (6, 3), (5, 4)]))    # killing
        self.assertTrue(g.makemove([(2, 1), (3, 0)]))    # valid now
        self.assertTrue(g.makemove([(7, 4), (6, 3)]))    # valid
        self.assertTrue(g.makemove([(3, 4), (4, 3)]))    # valid
        self.assertTrue(g.makemove([(6, 9), (5, 8)]))    # valid
        self.assertTrue(g.makemove([(3, 0), (4, 1)]))    # valid
        self.assertTrue(g.makemove([(6, 5), (5, 6)]))    # valid
        self.assertFalse(g.makemove([(4, 3), (5, 4), (6, 5), (5, 6), (4, 7)]))
        self.assertFalse(g.makemove([(4, 3), (5, 4), (6, 5), (5, 6), (4, 7),
                                     (5, 8)]))
        self.assertTrue(g.makemove([(4, 3), (5, 4), (6, 5), (5, 6), (4, 7),
                                    (5, 8), (6, 9)]))
        validboard = [
            list(' b b b b b'),  # 0
            list('b b b b b '),  # 1
            list(' . b b b b'),  # 2
            list('. b . b b '),  # 3
            list(' b . . . .'),  # 4
            list('w . . . . '),  # 5
            list(' . w . w b'),  # 6
            list('w . . w w '),  # 7
            list(' w w w w w'),  # 8
            list('w w w w w ')   # 9
        ]
        self.assertEqual(g.board, validboard)