def test_two_piece(self):
        board = Hive()
        piece1 = Spider(Color.WHITE)
        piece2 = Spider(Color.WHITE)
        board.add(piece1, HCP(0,0))
        board.add(piece2, HCP(1,0))

        open_locations = [HCP(1,1), HCP(0,1), HCP(-1,0),
                          HCP(0,-1), HCP(1,-1), HCP(-1,1),
                          HCP(2,0), HCP(2,-1)]

        self.assertEqual(set(board.edge()), set(open_locations))
    def test_hivebreak(self):
        board = Hive()

        piece1 = Spider(Color.WHITE)
        board.add(piece1, HCP(0,0))

        piece2 = Spider(Color.BLACK)
        board.add(piece2, HCP(1,0))

        piece3 = Spider(Color.BLACK)
        board.add(piece3, HCP(1,1))

        # These locations will break the hive
        breaker = [piece2, (1,0)]

        self.assertEqual(board.breaker(), breaker)
Beispiel #3
0
def make_sheet(hive):
    sheet = []
    for hcp in hive.locations():
        sheet.append(SheetHex(hcp))

    if sheet == []: sheet.append(SheetHex(HCP(0,0)))

    return sheet
Beispiel #4
0
    def mouse_movetype(self):

        while True:
            ptr = self.win.getMouse()
            for playerhex in self.playerhex_list:
                if playerhex.in_hitbox(ptr): 
                    return (Movetype.PLACE, playerhex.pawn, HCP(0,0))

            print "Elements on field: ", len(self.hivehex_dict)
            for hcp, hivehex in self.hivehex_dict.iteritems():
                print "\tType of pawn: ", type(hivehex.pawn)
                print "\tLocation of pawn: ", hivehex.hcp
                if hivehex.in_hitbox(ptr):
                    return (Movetype.MOVE, None, hcp)

        return (Movetype.PLACE, Ant(), HCP(0,0))
        pass
Beispiel #5
0
    def test_piece_removal(self):
        """ Test to see if pieces are removed from the players
        set of pieces """

        p1 = Player(Color.WHITE)
        hive = Hive()

        p1.place(Queen, HCP(0, 0), hive)

        self.assertFalse(p1.find(Queen))
Beispiel #6
0
    def test_place(self):
        """ test placement of moves
            
        Test to see if the a player can place a piece
        """
        p1 = Player(Color.WHITE)
        hive = Hive()

        p1.place(Ant, HCP(1, 1), hive)

        self.assertFalse(hive.empty())
    def test_boundries(self):        
        board = Hive()
        piece = Spider(Color.WHITE)
        board.add(piece, HCP(0,0))

        # Note that these are in the hive coordinate system.
        open_locations = [HCP(1,0), HCP(0,1), HCP(-1,0),
                          HCP(0,-1), HCP(1,-1), HCP(-1,1)]

        self.assertEqual(set(board.edge()),set(open_locations))
Beispiel #8
0
    def update(self, controller, player, hive):

        updatePlayer(player, self.win)

        draw_string("=====HIVE=====\n\n")
        draw_as_text(hive)
        draw_string("\n")
        draw_string("==============\n")
        draw_string("Move(0) or Place(1): ")

        movetype = controller.select([Movetype.MOVE, Movetype.PLACE])
        draw_string("\n")

        draw_string("What Piece?\n")

        if movetype == None:
            return True

        parameter1 = None

        if movetype == Movetype.MOVE:
            
            interior = hive.interior()
            draw_list(interior)
            location = controller.select(interior)
            
            parameter1 = location # From the tuplet get unique pawn

        if movetype == Movetype.PLACE:
            
            pieces = list(player.pawns)
            draw_list(pieces)
            piece = controller.select(pieces)
            
            parameter1 = piece #type(piece) # From the tuplet get unique pawn

        locations = hive.locations()

        if len(locations) == 0:
            locations = [HCP(0,0)]
    
        draw_string("To where\n")
        draw_list(locations)
        parameter2 = controller.select(locations)

        self.decision = Move(movetype, (parameter1, parameter2))

        draw_string("\n") 

        return self.decision != None
Beispiel #9
0
    def update(self, controller, player, hive):
        """ Update for command line
            
        When using the command line, the controller must make
        a decision immedienty. There are no update cycles or 
        checking if the mouse is hovering, just a hive and
        some basic input and output

        """ 
        draw_string("=====HIVE=====\n\n")
        draw_as_text(hive)
        draw_string("\n")
        draw_string("==============\n")
        draw_string("Move(0) or Place(1): ")
        move = controller.select([Movetype.MOVE, Movetype.PLACE])
        draw_string("\n")

        parameter1 = None

        if move == Movetype.MOVE:
            draw_string("What Piece?\n")
            
            pieces = hive.get_pieces()
            draw_list(pieces)
            piece = controller.select(pieces)
            
            parameter1 = pieces[1] # From the tuplet get unique pawn

        if move == Movetype.PLACE:
            draw_string("What Piece?\n")
            pieces = list(player.pawns)
            draw_list(pieces)
            piece = controller.select(pieces)
            parameter1 = type(piece) # From the tuplet get unique pawn

        draw_string("\n")
        locations = hive.locations()

        if len(locations) == 0:
            locations = [HCP(0,0)]    
        
        draw_string("To where\n")
        draw_list(locations)
        parameter2 = controller.select(locations)

        self.decision = (move, parameter1, parameter2)

        draw_string("\n")
        return self.decision != None 
    def test_starting_pawn(self):
        board = Hive()
        piece = Spider(Color.BLACK)
        board.add(piece, HCP(0,0))

        self.assertFalse(board.empty())