Exemple #1
0
def display():
    twDisplayInit();
    
    #twCameraShape();
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-FrustumWidth/2,FrustumWidth/2,
              -FrustumHeight/2,FrustumHeight/2,
              Near,Far);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    crosshairs();
    
    # set up a light facing forward.  It travels with us, like a
    # miner's light
    twGraySpotlight(GL_LIGHT1,(0,0,0,1),0,1,1,(0,0,-1),20,5)

    # now, set the camera where we really want it
    # twCameraPosition();
    gluLookAt(VRP[0],VRP[1],VRP[2],
              VRP[0]+VPN[0],VRP[1]+VPN[1],VRP[2]+VPN[2],
              0,1,0);

    Yard.draw()

    glFlush();
    glutSwapBuffers();       # necessary for animation
Exemple #2
0
 def printE(self,environment):
     for i in environment:
         for j in i:
             if type(j) is Yard:
                 print(Yard().symbol,end=" ")
             elif type(j) is Empty:
                 print(Empty().symbol,end=" ")
             elif type(j) is Robot:
                 print(Robot().symbol,end=" ")
             elif type(j) is Dirtiness:
                 print(Dirtiness().symbol,end=" ")
             elif type(j) is Obstacle:
                 print(Obstacle().symbol,end=" ")
             elif type(j) is Children:
                 print(Children().symbol,end=" ")
             elif type(j) is tuple and type(j[0]) is Yard and len(j) == 2:
                 if type(j[1]) is Children:
                     print(Yard().childrenSymbol,end=" ")
                 else:
                     print(Yard().robotSymbol,end=" ")
             elif type(j) is tuple and type(j[0]) is Yard and len(j) > 2:
                 print(Yard().childrenSymbol,end=" ")
             elif type(j) is tuple and type(j[0]) is Robot:
                 print(Robot().childrenSymbol,end=" ")
             elif type(j) is tuple and type(j[0]) is Dirtiness:
                 print(Robot().dirtinessSymbol,end=" ")
             else:
                 print('!')
         print()
     print('next turn')
Exemple #3
0
 def movWithoutChildren(self,environment,posRobot):
     possibleMoves = self.getPossibleMoves(environment,posRobot[0],posRobot[1],len(environment),len(environment[0]))
     if len(possibleMoves) > 0:
         if type(environment[posRobot[0]][posRobot[1]]) is tuple and len(environment[posRobot[0]][posRobot[1]]) > 2 and type(environment[posRobot[0]][posRobot[1]][1]) is Robot:
             environment[posRobot[0]][posRobot[1]] = (Yard(),Children(),self)
         elif not (self.typeCheck(possibleMoves,Children,environment) == (-1,-1)):
             pos = self.typeCheck(possibleMoves,Children,environment)
             environment[pos[0]][pos[1]] = (self,environment[pos[0]][pos[1]])
             if type(environment[posRobot[0]][posRobot[1]]) is Robot:
                 environment[posRobot[0]][posRobot[1]] = Empty()
             elif type(environment[posRobot[0]][posRobot[1]]) is tuple:
                 if type(environment[posRobot[0]][posRobot[1]][0]) is Dirtiness:
                     environment[posRobot[0]][posRobot[1]] = Dirtiness()
                 elif len(environment[posRobot[0]][posRobot[1]]) > 2:
                     environment[posRobot[0]][posRobot[1]] = (Yard(),Children())
                 else:
                     environment[posRobot[0]][posRobot[1]] = Yard()
         elif not (self.typeCheck(possibleMoves,Dirtiness,environment) == (-1,-1)):
             if type(environment[posRobot[0]][posRobot[1]]) is tuple and type(environment[posRobot[0]][posRobot[1]][0]) is Dirtiness:
                 environment[posRobot[0]][posRobot[1]] = self
             else:
                 pos = self.typeCheck(possibleMoves,Dirtiness,environment)
                 environment[pos[0]][pos[1]] = (environment[pos[0]][pos[1]],self)
                 if type(environment[posRobot[0]][posRobot[1]]) is tuple:
                     if len(environment[posRobot[0]][posRobot[1]]) > 2:
                         environment[posRobot[0]][posRobot[1]] = (Yard(),Children())
                     else:
                         environment[posRobot[0]][posRobot[1]] = Yard()
                 else:
                     environment[posRobot[0]][posRobot[1]] = Empty()
         else:
             if type(environment[posRobot[0]][posRobot[1]]) is tuple and type(environment[posRobot[0]][posRobot[1]][0]) is Dirtiness:
                     environment[posRobot[0]][posRobot[1]] = self
             else:
                 pos = self.chosePosition(self.getChildrenPosition(environment),possibleMoves)
                 if pos[0] == 1000000:
                     pos = self.chosePosition(self.getDirtinessPosition(environment),possibleMoves)
                 if pos[0] == 1000000:
                     return
                 if type(environment[pos[0]][pos[1]]) is Empty:
                     environment[pos[0]][pos[1]] = self
                     if type(environment[posRobot[0]][posRobot[1]]) is tuple:
                         if len(environment[posRobot[0]][posRobot[1]]) > 2:
                             environment[posRobot[0]][posRobot[1]] = (Yard(),Children())
                         else:
                             environment[posRobot[0]][posRobot[1]] = Yard()
                     else:
                         environment[posRobot[0]][posRobot[1]] = Empty()
                 else:
                     environment[pos[0]][pos[1]] = (Yard(),self)
                     if type(environment[posRobot[0]][posRobot[1]]) is tuple:
                         if len(environment[posRobot[0]][posRobot[1]]) > 2:
                             environment[posRobot[0]][posRobot[1]] = (Yard(),Children())
                         else:
                             environment[posRobot[0]][posRobot[1]] = Yard()
                     else:
                         environment[posRobot[0]][posRobot[1]] = Empty()
Exemple #4
0
def main():
    glutInit(sys.argv)
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
    twInitWindowSize(WinWidth,WinHeight);
    glutCreateWindow(sys.argv[0])
    twBoundingBox(BBXmin,BBXmax,BBYmin,BBYmax,BBZmin,BBZmax);
    glutDisplayFunc(display)
    twMainInit()
    Yard.drawInit()
  # the following two are after twMainInit to override its callback settings
    glutMouseFunc(myMouseFunction);
    glutMotionFunc(None);
    glutSpecialFunc(mySpecialFunction);
    glutReshapeFunc(None);      # Maybe in a future version
    glutMouseFunc(myMouseFunction);
    glutMainLoop();
Exemple #5
0
    def movWithChildren2(self,environment,posRobot):
        boolean = True
        possible = self.getPossibleMoves(environment,posRobot[0],posRobot[1],len(environment),len(environment[0]))
        possibleMoves = []
        for i in possible:
            if not (type(environment[i[0]][i[1]]) is Children):
                possibleMoves.append(i)
        yardPosition = self.getYardPosition(environment)
        # print(posRobot)
        # print(environment[posRobot[0]][posRobot[1]])
        # print(possibleMoves)
        pos = self.chosePosition(yardPosition,possibleMoves)
        if pos[0] == 1000000:
            return (pos,False)
        # print(pos)
        # print(environment[pos[0]][pos[1]])
        if type(environment[pos[0]][pos[1]]) is Dirtiness:
            environment[pos[0]][pos[1]] = (self,Children(),Dirtiness())
        elif type(environment[pos[0]][pos[1]]) is Empty:
            environment[pos[0]][pos[1]] = (self,Children())
        elif type(environment[pos[0]][pos[1]]) is Yard:
            environment[pos[0]][pos[1]] = (Yard(),self,Children)
            boolean = False

        if len(environment[posRobot[0]][posRobot[1]]) == 2 and type(environment[posRobot[0]][posRobot[1]][0]) is Robot:
            environment[posRobot[0]][posRobot[1]] = Empty()
        else:
            environment[posRobot[0]][posRobot[1]] = Dirtiness()
        
        return (pos,boolean)