Ejemplo n.º 1
0
    def __init__(self):
        self._loadWorld('./main.xml')
        self._loadSensor('./camera.rob')

        self.chessEngine = ChessEngine(self.world,
                                       self.world.terrain('tabletop'))
        self.chessEngine.loadPieces()
        self.chessEngine.loadBoard()

        self.chessEngine.arrangeBoard(90)
        self.chessEngine.arrangePieces()

        self._imageDir = 'image_dataset'

        self._colorDir = self._imageDir + '/color'
        self._depthDir = self._imageDir + '/depth'
        self._rectifiedDir = self._imageDir + '/rectified'

        self._metaDataFN = self._imageDir + '/metadata.csv'

        self._dirs = [
            self._imageDir, self._colorDir, self._depthDir, self._rectifiedDir
        ]

        self._colorFNFormat = self._colorDir + '/%06d_%02d.png'
        self._depthFNFormat = self._depthDir + '/%06d_%02d.png'
        self._rectifiedFNFormat = self._rectifiedDir + '/%06d.png'

        self._rectifiedPictureCorners = np.float32(
            [[DataUtils.IMAGE_SIZE, 0], [0, 0], [0, DataUtils.IMAGE_SIZE],
             [DataUtils.IMAGE_SIZE, DataUtils.IMAGE_SIZE]])
        self._boardWorldCorners = self.chessEngine.getBoardCorners()
Ejemplo n.º 2
0
 def setUp(self):
     self.camera = Camera(self.url)
     self.chessEngine = ChessEngine()
     self.board = 0
     self.current = 0
     self.previous = 0
     self.CPULastMove = "0"
Ejemplo n.º 3
0
    def test_move(self):
        commands_to_test = ['e4', 'e5', 'Qh5', 'Nc6', 'Bc4', 'Nf6']
        expected_results = []
        expected_results.append([[2,3,4,5,6,4,3,2],
                                 [1,1,1,1,0,1,1,1],
                                 [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,0,0,0,0,0,0],
                                 [7,7,7,7,7,7,7,7],
                                 [8,9,10,11,12,10,9,8]])
        expected_results.append([[2,3,4,5,6,4,3,2],
                                 [1,1,1,1,0,1,1,1],
                                 [0,0,0,0,0,0,0,0],
                                 [0,0,0,0,1,0,0,0],
                                 [0,0,0,0,7,0,0,0],
                                 [0,0,0,0,0,0,0,0],
                                 [7,7,7,7,0,7,7,7],
                                 [8,9,10,11,12,10,9,8]])
        expected_results.append([[2,3,4,0,6,4,3,2],
                                 [1,1,1,1,0,1,1,1],
                                 [0,0,0,0,0,0,0,0],
                                 [0,0,0,0,1,0,0,0],
                                 [0,0,0,0,7,0,0,5],
                                 [0,0,0,0,0,0,0,0],
                                 [7,7,7,7,0,7,7,7],
                                 [8,9,10,11,12,10,9,8]])
        expected_results.append([[2,3,4,0,6,4,3,2],
                                 [1,1,1,1,0,1,1,1],
                                 [0,0,0,0,0,0,0,0],
                                 [0,0,0,0,1,0,0,10],
                                 [0,0,0,0,7,0,0,5],
                                 [0,0,0,0,0,0,0,0],
                                 [7,7,7,7,0,7,7,7],
                                 [8,9,0,11,12,10,9,8]])
        expected_results.append([[2,3,4,0,6,0,3,2],
                                 [1,1,1,1,0,1,1,1],
                                 [0,0,0,0,0,0,0,0],
                                 [0,0,4,0,1,0,0,10],
                                 [0,0,0,0,7,0,0,5],
                                 [0,0,0,0,0,0,0,0],
                                 [7,7,7,7,0,7,7,7],
                                 [8,9,0,11,12,10,9,8]])
        expected_results.append([[2,3,4,0,6,0,3,2],
                                 [1,1,1,1,0,1,1,1],
                                 [0,0,0,0,0,0,0,0],
                                 [0,0,4,0,1,0,0,10],
                                 [0,0,0,0,7,0,0,5],
                                 [0,0,0,0,0,9,0,0],
                                 [7,7,7,7,0,7,7,7],
                                 [8,9,0,11,12,10,0,8]])

        # Create chess engine
        engine = ChessEngine()
        engine.set_board(self.initial_board_description)

        # Movement
        for move, result in zip(commands_to_test, expected_results):
            engine.parse(move)
            self.assertEqual(engine.board, expected_results)
Ejemplo n.º 4
0
 def __init__(self):
     pg.init()
     self.screen = pg.display.set_mode((WIDTH + TF_WIDTH, HEIGHT),
                                       pg.SRCALPHA, 32)
     self.clock = pg.time.Clock()
     pg.display.set_caption(TITLE)
     icon = pg.image.load(IMAGE_FILE_DICT["wR"])
     pg.display.set_icon(icon)
     self.load_data()
     self.engine = ChessEngine()
     self.AI = ChessAI(MAX_SEARCH_DEPTH)
Ejemplo n.º 5
0
    def test_set_board(self):
        expected_result = [[2,3,4,5,6,4,3,2],
                           [1,1,1,1,1,1,1,1],
                           [0,0,0,0,0,0,0,0],
                           [0,0,0,0,0,0,0,0],
                           [0,0,0,0,0,0,0,0],
                           [0,0,0,0,0,0,0,0],
                           [7,7,7,7,7,7,7,7],
                           [8,9,10,11,12,10,9,8]]

        # Create chess engine
        engine = ChessEngine()
        engine.set_board(self.initial_board_description)
        self.assertEqual(engine.board, expected_result)
Ejemplo n.º 6
0
import imutils
from BoardRecognition import BoardRecognition
from Board import Board
from ChessEngine import ChessEngine
from Game import Game

imgpath = '../board/28.jpg'
img = cv2.imread(imgpath)
img = imutils.resize(img, width=500)
cv2.imshow('img', img)

br = BoardRecognition(img)
thresh, img = br.cleanImage(img)
extracted = br.initializeMask(thresh, img)
edges, colorEdges = br.detectEdges(extracted)
horizontal, vertical = br.detectLines(edges, colorEdges)
corners = br.detectCorners(horizontal, vertical, colorEdges)
squares = br.detectSquares(corners, colorEdges)

board = Board(squares)
board.draw(img)
cv2.imshow('img2',img)
board.assignState()

engine = ChessEngine()
engine.updateMove('a2a4')
print()
engine.feedToAI()

#game = Game()
Ejemplo n.º 7
0
 def __init__(self, max_depth):
     self.color = "b"
     self.max_depth = max_depth
     self.engine = ChessEngine()
Ejemplo n.º 8
0
                    boardPhase.board_status[254-i]=tmp
                if boardPhase.player == 0:
                    boardPhase.player = 1
                else:
                    boardPhase.player = 0
            return     
"""

computer_first = False
pygame.mixer.pre_init(44100, 16, 2, 4096)
pygame.init()
boardWindow = BoardWindow(computer_first)
boardPhase = MCTSBoardPhase()
#boardPhase = BoardPhase()
boardWindow.drawBoard(boardPhase)
chessEngine = ChessEngine(3)
stop = False
train_flag = True
while True:
    if train_flag:
        pygame.event.pump()
        ret = boardWindow.computer_move(boardPhase, chessEngine)
        if not ret:
            boardPhase.reset()
    else:
        if computer_first and boardPhase.getSide() == 0 and not stop:
            if not boardWindow.computer_move(boardPhase, chessEngine):
                stop = True
        game_input(pygame.event.get(), boardWindow, boardWindow, chessEngine)
    boardWindow.drawBoard(boardPhase)
    pygame.display.flip()