Exemplo n.º 1
0
    def runHuman(self, depth, side):
        #@parm side: str -- "white" or "black"
        if side == "white":
            initMove = move.Move("a2a2")

            self.gameState()

            while True:
                moveStr = str(input("Your Move: "))
                humanMove = move.Move(moveStr)
                self.makeMove(humanMove)
                #print(nextMove.mString)
                #self.gameState()

                nextMove = self.negaMax(depth, BLACK, initMove)
                self.makeMove(nextMove)
                print(f"Jerry's move: {nextMove.mString}")
                self.gameState()

        if side == "black":
            initMove = move.Move("a2a2")

            self.gameState()

            while True:
                nextMove = self.negaMax(depth, WHITE, initMove)
                self.makeMove(nextMove)
                print(f"Jerry's move: {nextMove.mString}")
                self.gameState()

                moveStr = str(input("Your Move: "))
                humanMove = move.Move(moveStr)
                self.makeMove(humanMove)
Exemplo n.º 2
0
	def getMoves(self, board, ignoreCastles=False):
		moves = []

		## Check for castling
		if not ignoreCastles:
			if self.noMoves == 0 and not board.checkCheck(self.colour):
				kingSidePieces = [board.getPiece((i, self.coords[1])) for i in range(5, 8)]
				queenSidePieces = [board.getPiece((i, self.coords[1])) for i in range(0, 5)]
				if kingSidePieces[2] != False and kingSidePieces[2].noMoves == 0 and kingSidePieces[0] == False and kingSidePieces[1] == False:
					possible = True
					for x in range(6, 8):
						tempKing = King(self.colour, (x, self.coords[1]))
						board.piecesGroup.add(tempKing)
						if board.checkCheck(self.colour):
							possible = False
						board.piecesGroup.remove(tempKing)

					if possible:
						moves.append(move.Move((6, self.coords[1]), specialMove="Castle", thirdParty=(kingSidePieces[2], (5, self.coords[1]))))
				if queenSidePieces[0] != False and queenSidePieces[0].noMoves == 0 and queenSidePieces[1] == False and queenSidePieces[2] == False and queenSidePieces[3] == False:
					possible = True
					for x in range(1, 5):
						tempKing = King(self.colour, (x, self.coords[1]))
						board.piecesGroup.add(tempKing)
						if board.checkCheck(self.colour):
							possible = False
						board.piecesGroup.remove(tempKing)

					if possible:
						moves.append(move.Move((2, self.coords[1]), specialMove="Castle", thirdParty=(queenSidePieces[0], (3, self.coords[1]))))

		return moves + self.getStraightMoves(board, limit=1) + self.getDiagonalMoves(board, limit=1)
Exemplo n.º 3
0
	def getMoveThatFillsMainDiagonal(self, state, aSymbol):
		symbolCounter = 0
		emptyLine = 0
		emptyColumn = 0
		myMove = move.Move(0, 0)
		if state.emptyPosition(1, 1):
			emptyLine = 1
			emptyColumn = 1
		else:
			if (state.getValue(1, 1) == aSymbol):
				symbolCounter+=1
		if state.emptyPosition(2, 2):
			emptyLine = 2
			emptyColumn = 2
		else:
			if (state.getValue(2, 2) == aSymbol):
				symbolCounter+=1
		if state.emptyPosition(3, 3):
			emptyLine = 3
			emptyColumn = 3
		else:
			if (state.getValue(3, 3) == aSymbol):
				symbolCounter=symbolCounter+1
		if symbolCounter==2:
			myMove = move.Move(emptyLine, emptyColumn)
		return myMove
Exemplo n.º 4
0
	def getDiagonalMoves(self, board, limit=False):
		""" Gets all possible moves in the diagonals from a given piece.
		Returns a list of tuples, representing the co-ords which can be moved to."""
		possibleDirections = [(1,1), (-1,1), (1,-1), (-1,-1)]
		moves = []
		if not limit:
			for i in range(1, min([7-self.coords[0], 7-self.coords[1]]) + 1):
				moves.append(move.Move((self.coords[0] + i, self.coords[1] + i)))
				if not board.isSquareEmpty((self.coords[0] + i, self.coords[1] + i)):
					break
			for i in range(1, min([7-self.coords[0], self.coords[1]]) + 1):
				moves.append(move.Move((self.coords[0] + i, self.coords[1] - i)))
				if not board.isSquareEmpty((self.coords[0] + i, self.coords[1] - i)):
					break
			for i in range(1, min([self.coords[0], self.coords[1]]) + 1):
				moves.append(move.Move((self.coords[0] - i, self.coords[1] - i)))
				if not board.isSquareEmpty((self.coords[0] - i, self.coords[1] - i)):
					break
			for i in range(1, min([self.coords[0], 7-self.coords[1]]) + 1):
				moves.append(move.Move((self.coords[0] - i, self.coords[1] + i)))
				if not board.isSquareEmpty((self.coords[0] - i, self.coords[1] + i)):
					break
		else:
			for i in range(4):
				for j in range(1, limit+1):
					possibleMove = (self.coords[0]+(possibleDirections[i][0]*j), (self.coords[1]+(possibleDirections[i][1]*j)))
					moves.append(move.Move(possibleMove))
					if not board.isSquareEmpty((possibleMove[0], possibleMove[1])):
						break

		return moves
	def getMove3Way1(self, state):
		self.moveOrder+=1
		if state.emptyPosition(2, 1):
			myMove = self.getBasicMove(state)
		else:
			if ((state.emptyPosition(3, 2)) and (state.emptyPosition(3, 3))):
				myMove = move.Move(3, 3)
			else:
				myMove = move.Move(1, 3)
		return myMove
	def getMove3Way2(self, state):
		if state.emptyPosition(1, 2):
			myMove = self.getBasicMove(state)
		else:
			self.moveOrder+=1
			if (state.emptyPosition(2, 3)): 
				myMove = move.Move(3, 3)
			else:
				myMove = move.Move(3, 1)
		return myMove
	def getMove3Way3(self, state):
		if state.occupiedPosition(3, 1):
			self.moveOrder+=1
			myMove = move.Move(1, 3)
		else:
			if state.occupiedPosition(1, 3):
				self.moveOrder+=1
				myMove = move.Move(3, 1)
			else:
				myMove = self.getBasicMove(state)
		return myMove
	def getMove2(self, state):
		self.moveOrder+=1
		if state.occupiedPosition(2, 2):
			self.strategyWay = 3
			myMove = move.Move(3, 3)
		else:
			if ((state.occupiedPosition(2, 1)) or (state.occupiedPosition(2, 3)) or (state.occupiedPosition(3, 1)) ):
				self.strategyWay = 2
				myMove = move.Move(1, 3)
			else:
				self.strategyWay = 1
				myMove = move.Move(3, 1)
		return myMove
Exemplo n.º 9
0
def setup():
    mover = move.Move()
    mover.fight()
    mover.recharge()
    net = network.Network("", 8081)

    recThread = threading.Thread(target=net.startListening)
    recThread.start()

    while True:
        time.sleep(.1)
        if net.incomingVoiceText is not None:
            word = net.incomingVoiceText.lower()
            if "north" in word:
                mover.one_forward(2)
            if "south" in word:
                mover.one_backward(2)
            if "west" in word:
                mover.turn_left(1)
                mover.one_forward(2.5)
                mover.turn_right(.9)
            if "east" in word:
                mover.turn_right(1)
                mover.one_forward(2.5)
                mover.turn_left(1.1)
            if "fight" in word:
                mover.fight()
            if "recharge" in word:
                mover.recharge()
            net.incomingVoiceText = None
Exemplo n.º 10
0
    def knightMoves(self, row, col):
        #check all eight possible squares
        moveList = []

        if self.nextTurn == WHITE:
            sideConst = 1
        else:
            sideConst = -1

        #going clockwise starting with top right . . .

        rowAdd = [-2, -1, 1, 2, 2, 1, -1, -2]
        colAdd = [1, 2, 2, 1, -1, -2, -2, -1]

        for i in range(0, 8):
            inB = inBound(row + rowAdd[i], col + colAdd[i])
            if inB:
                tSquare = self.board[row + rowAdd[i]][col +
                                                      colAdd[i]] * sideConst
                if tSquare <= 0:
                    moveList.append(
                        move.Move([[row, col],
                                   [row + rowAdd[i], col + colAdd[i]]]))

        return moveList
Exemplo n.º 11
0
def demo_tour(odrv0) :
    move = m.Move(odrv0)
    # Fait  3 tours de carreaux (chez Martial)
    for i in range(0,12):
        move.translation(350)
        time.sleep(2)
        move.rotation(-90)
        time.sleep(2)
Exemplo n.º 12
0
	def all_possible_moves(self):
		options = []
		spaces = self._board.space_iterator()
		for space in spaces:
			act = move.Move(space)
			options.append(act)

		return options
Exemplo n.º 13
0
	def mateCheck(self, currentPlayer):
		if self.checkCheck(currentPlayer):
			for piece in self.piecesGroup.sprites():
				if piece.colour == currentPlayer:
					pieceCoords = piece.coords[:]

					for possibleMove in piece.getMoves(self):
						nextMove = possibleMove.coords
						if nextMove[0] > 0 and nextMove[1] > 0:
							if self.isSquareEmpty(nextMove):
								self.movePiece(piece, move.Move(nextMove))
								if not self.checkCheck(currentPlayer):
									print("No Take", piece.piece, piece.colour, nextMove)
									self.movePiece(piece, move.Move(pieceCoords))
									return False
								self.movePiece(piece, move.Move(pieceCoords))
							else:
								targetPiece = self.getPiece(nextMove)
								if targetPiece.colour != piece.colour:
									temp = targetPiece

									self.takePiece(piece, targetPiece, move.Move(nextMove))
									if not self.checkCheck(currentPlayer):
										print("Take", piece.piece, piece.colour, nextMove)
										self.piecesGroup.add(temp)
										self.movePiece(piece, move.Move(pieceCoords))
										return False
									self.piecesGroup.add(temp)
								self.movePiece(piece, move.Move(pieceCoords))
					self.movePiece(piece, move.Move(pieceCoords))
			return True
		return False
Exemplo n.º 14
0
	def getMoves(self, board):
		possibleDirections = [(2, 1), (2, -1), (-2, 1), (-2, -1), (1, 2), (1, -2), (-1, -2), (-1, 2)]
		moves = []

		for d in possibleDirections:
			possible = (self.coords[0] + d[0], self.coords[1] + d[1])
			moves.append(move.Move(possible))

		return moves
Exemplo n.º 15
0
	def getMove2(self, state):
		if (state.emptyPosition(3, 3)):
			self.strategyWay = 1
			myMove = self.getBasicMove(state)
		else:
			self.strategyWay = 2
			self.moveOrder+=1
			myMove = move.Move(3, 1)
		return myMove
Exemplo n.º 16
0
 def add(self, selection1):
     selection = m.Move(selection1.locat)
     x = selection.corner[0]
     y = selection.corner[1]
     #print("corner =" , selection.corner)
     for r in range(len(selection.layout)):
         for c in range(len(selection.layout[r])):
             self.board[r + y][c + x] = (self.board[r + y][c + x] +
                                         selection.layout[r][c]) % 2
Exemplo n.º 17
0
    def createMoveJabAPart2(self):
        f = [ self.frameData(14, 6),
              self.frameData(15, 30)]

        t = [ ['releaseA', move.Transition(-1, None, 1, 1, 'throw2')],
              ['exitFrame', move.Transition(-1, None, None, None, 'throw2')]]

        self.moves['jabA2'] = move.Move(f, t)
        self.moves['jabA2'].canDI = False
Exemplo n.º 18
0
def demo_simple(odrv0) :

    move = m.Move(odrv0)

    time.sleep(1)
    move.translation(1500)
    time.sleep(2)
    move.rotation(180)
    time.sleep(2)
    move.translation(1000)
Exemplo n.º 19
0
    def createMoveThrow1(self):
        f = [ self.frameData(11, 3),
              self.frameData(12, 1),
              self.frameData(13, 9) ]

        self.moves['throw1'] = move.Move(f, [])
        self.moves['throw1'].canDI = False
        self.moves['throw1'].shoot.append( (1, 0, (35, -46)) )
        self.moves['throw1'].shoot.append( (1, 1, (35, -46)) )
        self.moves['throw1'].shoot.append( (1, 2, (35, -46)) )
Exemplo n.º 20
0
 def click(self, line, column):
     if (self.getStatus() == 1):
         self.startMatch()
     else:
         if (self.getStatus() == 2 or self.getStatus() == 3):
             aMove = move.Move(line, column)
             self.proceedMove(aMove)
         else:
             if (self.getStatus() == 4 or self.getStatus() == 5):
                 self.reset()
Exemplo n.º 21
0
 def allmoves(self, color, pos=None):
     l = []
     if not pos:
         for row in self.squares:
             for s in row:
                 if s.p.color == color:
                     for li in self.squares:
                         for e in li:
                             m = move.Move(self, s.coord, e.coord)
                             if m.is_legal():
                                 l.append(m)
     else:
         s = self.squares[pos[0]][pos[1]]
         for li in self.squares:
             for e in li:
                 m = move.Move(self, s.coord, e.coord)
                 if m.is_legal():
                     l.append(m)
     return l
Exemplo n.º 22
0
	def getAnyPossibleMove(self, state):
		myMove = None
		for x in range(3):
			aLine=x+1
			for y in range(3):
				aColumn=y+1
				if state.emptyPosition(aLine, aColumn):
					
					myMove = move.Move(aLine, aColumn)
					return myMove
		return myMove
Exemplo n.º 23
0
def takeback():
    if b.last_move != None:
        if len(b.last_move) == 2:
            laststart, lastfinish = b.last_move[0], b.last_move[1]
            backmove = move.Move(b, lastfinish.coord, laststart.coord)
            b.update(backmove)
            b.append_piece(lastfinish.p, *lastfinish.coord)
        if len(b.last_move) == 4:
            laststart1, lastfinish1 = b.last_move[0], b.last_move[1]
            laststart2, lastfinish2 = b.last_move[2], b.last_move[3]
            backmove2 = move.Move(b, lastfinish2.coord, laststart2.coord)
            backmove1 = move.Move(b, lastfinish1.coord, laststart1.coord)
            b.update(backmove2)
            b.update(backmove1)
        if len(b.last_move) == 3:
            laststart, lastfinish = b.last_move[0], b.last_move[1]
            b.append_piece(piece.Pawn(b.last_move[2]), *lastfinish.coord)
            backmove = move.Move(b, lastfinish.coord, laststart.coord)
            b.update(backmove)
            b.append_piece(lastfinish.p, *lastfinish.coord)
Exemplo n.º 24
0
 def preStitch(self):
     ANGLE = 360 / constants.STITCH_COUNT
     m = move.Move()
     for i in range(constants.STITCH_COUNT):
         m.stop()
         rospy.sleep(0.5)
         cv2.imwrite(
             constants.STITCH_IMAGE_COMMON_PATH_PREFIX + str(i) + ".png",
             self.image)
         m.rotate("right", ANGLE)
     m.stop()
Exemplo n.º 25
0
	def getStraightMoves(self, board, limit=8):
		""" Gets all possible moves in the horizontal and vertical directions from a given piece.
		Returns a list of tuples, representing the co-ords which can be moved to."""
		directions = [(1, 0), (-1, 0), (0, 1), (0, -1)]
		moves = []

		for d in directions:
			distance = 1
			nextMove = (self.coords[0] + distance*d[0], self.coords[1] + distance*d[1])
			while distance <= limit and board.isSquareEmpty(nextMove) and nextMove[0] in range(0, 8) and nextMove[1] in range(0, 8):
				moves.append(move.Move(nextMove))

				distance += 1
				nextMove = (self.coords[0] + distance*d[0], self.coords[1] + distance*d[1])
			if not board.isSquareEmpty(nextMove):
				moves.append(move.Move(nextMove))

		for m in moves:
			if m.coords[0] < 0 or m.coords[1] < 0:
				moves.remove(m)
		return moves
Exemplo n.º 26
0
 def range(self, color):
     l = set()
     for row in self.squares:
         for s in row:
             if s.p.color == color:
                 for li in self.squares:
                     for e in li:
                         m = move.Move(self, s.coord, e.coord)
                         m.is_possible()
                         if m.taking:
                             l.add(m.finish)
     return l
Exemplo n.º 27
0
	def movePiece(self, piece, moveObj):
		piece.coords[0] = moveObj.coords[0]
		piece.coords[1] = moveObj.coords[1]
		piece.rect.x = piece.coords[0] * SQUAREWIDTH
		piece.rect.y = piece.coords[1] * SQUAREWIDTH

		if moveObj.specialMove == "Castle":
			self.movePiece(moveObj.thirdParty[0], move.Move(moveObj.thirdParty[1]))
		elif moveObj.specialMove == "EP":
			self.takePiece(piece, moveObj.thirdParty, moveObj, EP=True)

		piece.noMoves += 1
Exemplo n.º 28
0
	def getMoveThatFillsColumn(self, state, aSymbol):
		symbolCounter = 0
		emptyLine = 0
		emptyColumn = 0
		myMove = move.Move(0, 0)
		for y in range(3):
			aColumn=y+1
			if (state.occupiedPositionsOnTheColumn(aColumn) == 2):
				symbolCounter = 0
				emptyLine = 0
				emptyColumn = 0
				for x in range(3):
					aLine = x+1
					if state.emptyPosition(aLine, aColumn):
						emptyLine = aLine
						emptyColumn = aColumn
					else:
						if (state.getValue(aLine, aColumn) == aSymbol):
							symbolCounter=symbolCounter+1
				if symbolCounter==2:
					myMove = move.Move(emptyLine, emptyColumn)
		return myMove
Exemplo n.º 29
0
    def pawnMoves(self, row, col):  #TODO Promotions
        #1. check if pawn is in starting positon based on what side its on
        #2. if so, give ability to move up two squares
        moveList = []
        if self.nextTurn == WHITE:

            # check if this is a promotion move
            if row == 1: promotion = True
            else: promotion = False

            if self.board[row - 1][col] == 0:
                moveList.append(
                    move.Move([[row, col], [row - 1, col]], promotion))
            if row == 6:  # handle checking for double jumping for pawn--WHITE
                if self.board[row - 2][col] == 0:
                    moveList.append(move.Move([[row, col], [row - 2, col]]))

            # checking if black pieces are in immediate diag
            if col > 0:
                if self.board[row - 1][col - 1] < 0:
                    moveList.append(
                        move.Move([[row, col], [row - 1, col - 1]], promotion))
            if col < 7:
                if self.board[row - 1][col + 1] < 0:
                    moveList.append(
                        move.Move([[row, col], [row - 1, col + 1]], promotion))

        else:  #BLACK TODO add sideConst method to this

            # check if this is a promotion move
            if row == 6: promotion = True
            else: promotion = False

            if self.board[row + 1][col] == 0:
                moveList.append(move.Move([[row, col], [row + 1, col]]))
            if row == 1:
                if self.board[row + 2][col] == 0:
                    moveList.append(move.Move([[row, col], [row + 2, col]]))

            # checking if white pieces are in imediate diag
            if col > 0:
                if self.board[row + 1][col - 1] > 0:
                    moveList.append(
                        move.Move([[row, col], [row + 1, col - 1]], promotion))
            if col < 7:
                if self.board[row + 1][col + 1] > 0:
                    moveList.append(
                        move.Move([[row, col], [row + 1, col + 1]], promotion))
        return moveList
Exemplo n.º 30
0
def run_test(odrv0) :
    # Strategie proposé de parcour
    com = Communication('/dev/ttyACM0')
    move = m.Move(odrv0)
    print("Initialisation des Actionneurs...")
    com.waitEndMove(Communication.MSG["Initialisation"], True)
    print("Initilisation DONE")
    time.sleep(1)

    print("Palet_Floor_In...")
    com.send(Communication.MSG["Palet_Floor_In"])
    print("Waiting moving forward...")
    while not com.Avancer:
        com.read(True)
    time.sleep(.1)

    #ICI ON AVANCE
    move.translation(500)
    print("Moving forward DONE")
    com.send(Communication.MSG["Action_Finished"])
    print("Waiting moving backward...")
    while not com.Reculer:
        com.read(True)
    time.sleep(.1)

    #ICI ON TOURNE
    move.rotation(-90)
    print("Rotation DONE")
    com.send(Communication.MSG["Action_Finished"])
    print("Waiting end of movement.")
    while not com.readyNext:
        com.read(True)

    #ICI ON RECULE
    move.translation(-500)
    print("Moving backward DONE")
    com.send(Communication.MSG["Action_Finished"])
    print("Waiting end of movement.")
    while not com.readyNext:
        com.read(True)
    print("Palet_Floor_In DONE.")
    time.sleep(1)

    print("Transport...")
    com.waitEndMove(Communication.MSG["Transport"], True)
    print("Transport DONE")
    time.sleep(1)

    print("Turn off robot...")
    com.send(Communication.MSG["Arret"])
    print("Robot is turned off!")