def spawnPiece(self, piecetype, team, x, y, z, d):
     col = color.white
     if (team == 1):
         col = color.red
     if (piecetype == 'pawn'):
         self.addPiece(x, y, z, d,
                       piece.Pawn(vector(x, y, z), col, self.spots))
     if (piecetype == 'knight'):
         self.addPiece(x, y, z, d,
                       piece.Knight(vector(x, y, z), col, self.spots))
     if (piecetype == 'rook'):
         self.addPiece(x, y, z, d,
                       piece.Rook(vector(x, y, z), col, self.spots))
     if (piecetype == 'bishop'):
         self.addPiece(x, y, z, d,
                       piece.Bishop(vector(x, y, z), col, self.spots))
     if (piecetype == 'king'):
         self.addPiece(x, y, z, d,
                       piece.King(vector(x, y, z), col, self.spots))
         if (col == color.red):
             self.redkingpos = fvec.Fvector(x, y, z, d)
         else:
             self.whitekingpos = fvec.Fvector(x, y, z, d)
     if (piecetype == 'queen'):
         self.addPiece(x, y, z, d,
                       piece.Queen(vector(x, y, z), col, self.spots))
 def movePiece(self, fx, fy, fz, fd, tx, ty, tz, td):
     'Takes pice from square fx,fy and moves to tx,ty'
     'Checks if piece exists on square'
     piec = self.spots[fd][fz][fy][fx]
     if piece == None:
         return
     topiece = self.spots[td][tz][ty][tx]
     if topiece != None:
         if (self.currcol == color.white):
             self.redscore -= topiece.score
         else:
             self.whitescore -= topiece.score
         topiece.setvisible(0)
     y = piec.base.pos.y - (2.5 * fy)
     if (piec.move(vector(tx, y + ty * 2.5, tz + (5 * td)))):
         self.selectedpiece = None
         piec.select()
         self.spots[fd][fz][fy][fx] = None
         self.spots[td][tz][ty][tx] = piec
         if (isinstance(piec, piece.King)):
             if (piec.ogcolor == color.red):
                 self.redkingpos = fvec.Fvector(tx, ty, tz, td)
             else:
                 self.whitekingpos = fvec.Fvector(tx, ty, tz, td)
         #if(isinstance(piec,piece.Pawn)):
         #self.promote(piec)
         piec.unglow()
     if (topiece != None and isinstance(topiece, piece.King)):
         self.gameover = True
         self.winner = 'red' if self.currcol == color.red else 'white'
Exemple #3
0
 def getpos(self):
     x = round(self.base.pos.x)
     y = round(ytoy(self.base.pos.y))
     z = round(ztoz(self.base.pos.z))
     d = round(ztod(self.base.pos.z))
     self.posvec = fvec.Fvector(x,y,z,d)
     return self.posvec
Exemple #4
0
    def getpositions(self,x,y,z,d,board):
        self.posvec = fvec.Fvector(x,y,z,d)
        positions = self.posvec.getPosArray(1,1,0,0,False,board)
        positions+= self.posvec.getPosArray(1, 0, 1, 0,False,board)
        positions+= self.posvec.getPosArray(1, 0, 0, 1,False,board)
        positions+= self.posvec.getPosArray(0, 1, 1, 0,False,board)
        positions+= self.posvec.getPosArray(0, 1, 0, 1,False,board)
        positions+= self.posvec.getPosArray(0, 0, 1, 1,False,board)

        positions+= self.posvec.getPosArray(-1, 1, 0, 0,False,board)
        positions+= self.posvec.getPosArray(-1, 0, 1, 0,False,board)
        positions+= self.posvec.getPosArray(-1, 0, 0, 1,False,board)
        positions+= self.posvec.getPosArray(0, -1, 1, 0,False,board)
        positions+= self.posvec.getPosArray(0, -1, 0, 1,False,board)
        positions+= self.posvec.getPosArray(0, 0, -1, 1,False,board)

        positions+= self.posvec.getPosArray(1, -1, 0, 0,False,board)
        positions+= self.posvec.getPosArray(1, 0, -1, 0,False,board)
        positions+= self.posvec.getPosArray(1, 0, 0, -1,False,board)
        positions+= self.posvec.getPosArray(0, 1, -1, 0,False,board)
        positions+= self.posvec.getPosArray(0, 1, 0, -1,False,board)
        positions+= self.posvec.getPosArray(0, 0, 1, -1,False,board)

        positions+= self.posvec.getPosArray(-1, -1, 0, 0,False,board)
        positions+= self.posvec.getPosArray(-1, 0, -1, 0,False,board)
        positions+= self.posvec.getPosArray(-1, 0, 0, -1,False,board)
        positions+= self.posvec.getPosArray(0, -1, -1, 0,False,board)
        positions+= self.posvec.getPosArray(0, -1, 0, -1,False,board)
        positions+= self.posvec.getPosArray(0, 0, -1, -1,False,board)
        self.positions = positions
        return positions
Exemple #5
0
 def move(self,newPos):
     self.base.pos = newPos
     self.x = round(self.base.pos.x)
     self.y = round(ytoy(self.base.pos.y))
     self.z = round(ztoz(self.base.pos.z))
     self.d = round(ztod(self.base.pos.z))
     self.posvec = fvec.Fvector(self.x,self.y,self.z,self.d)
     self.base.color = self.ogcolor
     self.started=True
     return True
 def moveMousePiece(self):
     obj = scene.mouse.pick
     if (obj != None):
         fx = round(self.selectedpiece.base.pos.x)
         fy = round(self.ytoy(self.selectedpiece.base.pos.y))
         fz = round(self.ztoz(self.selectedpiece.base.pos.z))
         fd = round(self.ztod(self.selectedpiece.base.pos.z))
         fromvec = fvec.Fvector(fx, fy, fz, fd)
         pos = obj.pos
         bx = round(pos.x)
         by = round(self.ytoy(pos.y))
         bz = round(self.ztoz(pos.z))
         bd = round(self.ztod(pos.z))
         boardvec = fvec.Fvector(bx, by, bz, bd)
         piece = self.spots[fd][fz][fy][fx]
         if (fromvec == boardvec):
             self.selectedpiece = None
             piece.select()
             piece.base.color = piece.ogcolor
             piece.unglow()
             return False
         tx = round(pos.x)
         ty = round(self.ytoy(pos.y))
         tz = round(self.ztoz(pos.z))
         td = round(self.ztod(pos.z))
         tovec = fvec.Fvector(tx, ty, tz, td)
         if (tovec in piece.positions):
             self.movePiece(fx, fy, fz, fd, tx, ty, tz, td)
             return True
         else:
             self.selectedpiece = None
             piece.select()
             piece.base.color = piece.ogcolor
             piece.unglow()
             return False
     else:
         self.selectedpiece.select()
         self.selectedpiece.base.color = self.selectedpiece.ogcolor
         self.selectedpiece.unglow()
         self.selectedpiece = None
         return False
Exemple #7
0
 def __init__(self,spos,sColor,board):
     self.board = board
     self.score = 1e8
     self.started=False
     self.selected = False
     self.ogcolor = sColor
     self.boxes = []
     self.base = compound([cylinder(pos=spos+vector(0,0,0),radius=0.4,length=1.2,axis=vector(0,1,0),color=sColor),box(height=0.6,width=0.6,length=0.6,pos=spos+vector(0,1.5,0),color=sColor)])
     self.x = round(self.base.pos.x)
     self.y = round(ytoy(self.base.pos.y))
     self.z = round(ztoz(self.base.pos.z))
     self.d = round(ztod(self.base.pos.z))
     self.posvec = fvec.Fvector(self.x,self.y,self.z,self.d)
def recpickmove(currnode, switchcol):
    boards = []
    ogboard = copy(currnode.board)
    cloc = (color.red if currnode.ccol == color.white else
            color.white) if switchcol else currnode.ccol
    kingpos = currnode.redkingpos if currnode.ccol == color.red else currnode.whitekingpos
    moves = possiblemoves(currnode.board, currnode.ccol, kingpos)
    redscore = currnode.redscore
    whitescore = currnode.whitescore
    i = 0
    for movec in moves:
        redscore = currnode.redscore
        whitescore = currnode.whitescore
        board = copy(ogboard)
        frovec = movec.getfromvec()
        tvec = movec.gettovec()
        piec = board[frovec.d][frovec.z][frovec.y][frovec.x]
        if piec == None:
            continue
        topiece = board[tvec.d][tvec.z][tvec.y][tvec.x]
        if topiece != None:
            if (currnode.ccol == color.white):
                redscore -= topiece.score
            else:
                whitescore -= topiece.score
        board[frovec.d][frovec.z][frovec.y][frovec.x] = None
        board[tvec.d][tvec.z][tvec.y][tvec.x] = piec
        piec.started = True
        newboard = node.Node(board, movec, redscore, whitescore, cloc)
        if (isinstance(piec, piece.King)):
            if (piec.ogcolor == color.red):
                newboard.redkingpos = fvec.Fvector(tvec.x, tvec.y, tvec.z,
                                                   tvec.d)
            else:
                newboard.whitekingpos = fvec.Fvector(tvec.x, tvec.y, tvec.z,
                                                     tvec.d)
        boards.append(newboard)
    return boards
Exemple #9
0
 def getpositions(self,x,y,z,d,board):
     self.posvec = fvec.Fvector(x,y,z,d)
     c = -1
     if(self.ogcolor.equals(color.white)):
         c = 1
     self.positions = None
     positions = self.posvec.pawn(0,0,c,0,True,board)
     if(not self.started):
         positions+=self.posvec.pawn(0,0,c,0,False,board)
     positions+=self.posvec.pawn(1,0,c,0,True,board)
     positions+=self.posvec.pawn(-1,0,c,0,True,board)
     positions+=self.posvec.pawn(0,1,c,0,True,board)
     positions+=self.posvec.pawn(0,-1,c,0,True,board)
     positions+=self.posvec.pawn(0,0,c,c,True,board)
     self.positions = positions
     return positions
Exemple #10
0
 def __init__(self,spos,sColor,board):
     self.board = board
     self.score = 1
     self.started=False
     self.selected = False
     #self.base = compound([cone(pos=(spos),radius=0.4,axis=vector(0,1,0),color=sColor),
     #sphere(pos=(spos)+vector(0,1,0),radius=0.1,axis=vector(0,1,0),color=sColor)])
     self.base = cone(pos=(spos),radius=0.4,axis=vector(0,1,0),color=sColor)
     self.ogcolor = sColor
     self.boxes = []
     self.positions = None
     self.x = round(self.base.pos.x)
     self.y = round(ytoy(self.base.pos.y))
     self.z = round(ztoz(self.base.pos.z))
     self.d = round(ztod(self.base.pos.z))
     self.posvec = fvec.Fvector(self.x,self.y,self.z,self.d)
Exemple #11
0
 def __init__(self,spos,sColor,board):
     self.board = board
     self.score = 3
     self.started=False
     self.selected = False
     self.ogcolor = sColor
     self.boxes = []
     face = 0.1
     if(sColor == color.red):
         face = -0.1
     self.base = compound([box(pos=spos+(vector(0,0.4,0)),width=0.4,length=0.8,height=0.4,axis=vector(0,1,0),color=sColor),
     box(pos=spos+(vector(0,0.8,face)),width=0.6,length=0.4,height=0.4,axis=vector(0,1,0),color=sColor)])
     #cone(pos=spos+vector(0,0.6,0),radius=0.2,axis=vector(0,0,face),color=sColor)])
     self.x = round(self.base.pos.x)
     self.y = round(ytoy(self.base.pos.y))
     self.z = round(ztoz(self.base.pos.z))
     self.d = round(ztod(self.base.pos.z))
     self.posvec = fvec.Fvector(self.x,self.y,self.z,self.d)
Exemple #12
0
 def completepositions(self,x,y,z,d,kingpos,board):
     nowvec = fvec.Fvector(x,y,z,d)
     return nowvec.removecheckpos(self,board,kingpos)