Esempio n. 1
0
def check_events(gameStatus, screen, hole_size, board):
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        if event.type == pygame.MOUSEBUTTONUP:
            mouse_x, mouse_y = pygame.mouse.get_pos()
            x = math.floor(mouse_x / hole_size)
            y = math.floor(mouse_y / hole_size)
            if check_avaliable(gameStatus, x, y, board, True):
                # mention that available table is not match true board, it is diagonally flipped
                gameStatus.available[x][y] = 1
                gameStatus.occupy[x][y] = gameStatus.turn
                marble = Marble(screen, gameStatus)
                marble.blitme_xy(int((x + 0.5) * hole_size), int((y + 0.5) * hole_size))
                if gameStatus.turn == 1:
                    gameStatus.turn = 0
                else:
                    gameStatus.turn = 1
                gameStatus.last_opponent = (x, y)
                # calculate score
                calculate_score(gameStatus, board)
                print("red score:", gameStatus.red_score, "black score:", gameStatus.black_score)
                # check game end
                if check_end(gameStatus, board, x, y):
                    gameStatus.end = True
Esempio n. 2
0
    def __init__(self,conf,mode,verbose=False,max_artists=sys.maxint):
        # initialize the superclass
        Marble.__init__(self,conf,mode,verbose,max_artists)
        
        self.initialize_weights()
        self.em_iter = self.conf["em"]["iter"]

        self.neigh = NearestNeighbors(n_neighbors=self.conf["em"]["neighbors"],metric=self.conf["em"]["metric"])
Esempio n. 3
0
    def test_print_node(self):
        marble = Marble(0)
        marble.add_next(marble)
        marble1 = Marble(1)
        marble.add_next(marble1)

        print marble.print_marble()
        print marble1.print_marble()
Esempio n. 4
0
 def move_by(self,
             src: Union[House, int],
             marble: Marble,
             movements: int,
             number: int = 1) -> bool:
     return self.move_marble(src, marble.get_destination(src, movements),
                             marble, number)
Esempio n. 5
0
 def put_marble(self, x, y):
     if bf.check_avaliable(self.gameStatus, x, y, self.board, True):
         # mention that available table is not match true board, it is diagonally flipped
         self.gameStatus.available[x][y] = 1
         self.gameStatus.occupy[x][y] = self.gameStatus.turn
         marble = Marble(self.screen, self.gameStatus)
         marble.blitme_xy(int((x + 0.5) * self.hole_size), int((y + 0.5) * self.hole_size))
         if self.gameStatus.turn == 1:
             self.gameStatus.turn = 0
         else:
             self.gameStatus.turn = 1
         self.gameStatus.last_opponent = (x, y)
         # calculate score
         bf.calculate_score(self.gameStatus, self.board)
         print("red score:", self.gameStatus.red_score, "black score:", self.gameStatus.black_score)
         # check game end
         if bf.check_end(self.gameStatus, self.board, x, y):
             self.gameStatus.end = True
Esempio n. 6
0
 def can_move(self,
              src: Union[House, int],
              dst: Union[House, int],
              marble: Marble,
              number: int = 1):
     src, dst = self.get_house(src), self.get_house(dst)
     return bool(src and dst and src.is_host(marble)
                 and src.marble_counter(marble) >= number
                 and marble.has_progressive_movements(int(src), int(dst))
                 and dst.can_add(marble))
Esempio n. 7
0
    def __init__(self, data, colour, locations, triangles):
        '''Initialises a Player object:
            Sets the direction, type
            Creates 10 marbles with locations and colour'''

        self._direction = data[0]
        self._locations = locations
        marble_locations = data[1]
        self._marbles = [
            Marble(location, colour) for location in marble_locations
        ]
        self._type = 'Generic'
Esempio n. 8
0
    def __init__(self, position):
        """Initialise pot with 4 marbles unless position 6 or 13.

        Args:
            position : int of pot index, 6 or 13 initialise empty.

        """
        self.position = position
        # Generate marbles
        if position in [6, 13]:
            self.marbles = []
        else:
            self.marbles = [Marble() for _ in range(4)]
Esempio n. 9
0
    def test_addMarble(self):
        mb = MarbleBag()
        mb.addMarble(Marble())
        marbs = mb.getMarbles()
        for i in range(len(marbs)):
            with self.subTest():
                pass

        with self.subTest():
            marbs = mb.getMarbles()
            self.assertIsInstance(marbs[0], Marble)
            for i in range(1, len(marbs)):
                self.AssertEqual(marbs[i], None)
Esempio n. 10
0
def main():
    '''
  Input
  428 players; last marble is worth 70825 points

  Examples
  9 players; last marble iw worth 25 points: high score is 32
  10 players; last marble is worth 1618 points: high score is 8317    X
  13 players; last marble is worth 7999 points: high score is 146373  X
  17 players; last marble is worth 1104 points: high score is 2764    X
  21 players; last marble is worth 6111 points: high score is 54718   X
  30 players; last marble is worth 5807 points: high score is 37305   X
  '''

    playerCount = 428
    finishMarbleScore = 70825 * 100

    playerScores = [0] * playerCount
    startMarble = Marble(0)
    firstMarble = Marble(1, startMarble, startMarble)
    startMarble.next = firstMarble
    startMarble.prev = firstMarble

    curMarbleVal = 1
    curMarble = firstMarble
    curPlayer = 0
    marbleCount = 2

    while (curMarbleVal < finishMarbleScore):
        curMarbleVal += 1
        print(curMarbleVal * 100 / finishMarbleScore)
        if curPlayer == playerCount - 1:
            curPlayer = 0
        else:
            curPlayer += 1

        if curMarbleVal % 23 == 0:
            score = curMarbleVal
            nextMarble = curMarble
            for n in range(7):
                nextMarble = nextMarble.prev

            score += nextMarble.value
            curMarble = nextMarble.next
            nextMarble.prev.next = nextMarble.next
            nextMarble.next.prev = nextMarble.prev
            playerScores[curPlayer] += score
        else:
            nextMarble = curMarble.next
            newMarble = Marble(curMarbleVal)
            nextMarble.addAfter(newMarble)
            curMarble = newMarble
            marbleCount += 1

    print("high score", max(playerScores))  #398502
Esempio n. 11
0
    def __init__(self,conf,mode="train",verbose=False,max_artists=sys.maxint):
        # initialize the superclass
        Marble.__init__(self,conf,mode,verbose,max_artists)

        self.clf = MLPClassifier(hidden_layer_sizes=tuple(self.conf["mlp"]["hidden_layer_sizes"]),max_iter=self.conf["mlp"]["max_iter"])
        self.neigh = NearestNeighbors(n_neighbors=self.conf["mlp"]["neighbors"],metric=self.conf["mlp"]["metric"])
Esempio n. 12
0
 def test_defaut(self):
     m = Marble()
     self.assertEqual(m.getSize(), 5)
     self.assertEqual(m.getColor(), "red")
Esempio n. 13
0
 def test_getMarble(self):
     mb = MarbleBag()
     mb.addMarble(Marble())
     self.assertIsInstance(mb.getMarble(1), Marble)
Esempio n. 14
0
	def randomFillBag(self):
		colors = ["red", "green", "blue"]
		for i in range(len(self.marbles)):
			self.marbles[i] = Marble(color=colors[random.randint(0,len(colors)-1)], size=random.randint(1,10))
Esempio n. 15
0
    def __init__(self,conf,mode="train",verbose=False,max_artists=sys.maxint):
        # initialize the superclass
        Marble.__init__(self,conf,mode,verbose,max_artists)

        self.kmeans = KMeans(n_clusters=conf["kmeans"]["num_clusters"])