コード例 #1
0
    def getStrikeMoves(self):
        if self.isTerminal():
            return set()

        # get player/opponent
        if self.turn == 1:
            player = self.p1
            opp = self.p2
        else:
            player = self.p2
            opp = self.p1

        pHands = [player.left, player.right]

        # strike move
        attackingPHands = [hand for hand in pHands if hand > 0]
        nextPlayerStates = [PlayerState(player.left, player.right)]
        nextOppStates = [
            PlayerState(opp.left, (pHand + opp.right) % 5)
            for pHand in attackingPHands
        ] + [
            PlayerState((pHand + opp.left) % 5, opp.right)
            for pHand in attackingPHands
        ]
        return set([
            GameState(pState, oppState, self.nextTurn())
            if self.turn == 1 else GameState(oppState, pState, self.nextTurn())
            for pState in nextPlayerStates for oppState in nextOppStates
        ])
コード例 #2
0
    def getSplitMoves(self):
        if not self.canSplit() or self.isTerminal():
            return set()

        # get player/opponent
        if self.turn == 1:
            player = self.p1
            opp = self.p2
        else:
            player = self.p2
            opp = self.p1

        # get possible split moves
        if player.left == 0:
            nextPlayerStates = [
                PlayerState(player.left + i, player.right - i)
                for i in range(1, player.right)
            ]
        else:
            nextPlayerStates = [
                PlayerState(player.left - i, player.right + i)
                for i in range(1, player.left)
            ]

        nextOppStates = [PlayerState(opp.left, opp.right)]
        return set([
            GameState(pState, oppState, self.nextTurn())
            if self.turn == 1 else GameState(oppState, pState, self.nextTurn())
            for pState in nextPlayerStates for oppState in nextOppStates
        ])
コード例 #3
0
ファイル: GameState.py プロジェクト: odabugs/kof13-hitboxes
class GameState:
    def __init__(self, environment):
        self.env = environment
        self.process = self.env.process
        self.p1 = PlayerState(self.env, 1, P1_PTR, P1_TEAM_PTR, P1_HBS)
        self.p2 = PlayerState(self.env, 2, P2_PTR, P2_TEAM_PTR, P2_HBS)
        self.camera = GAME_CAMERA()

    def update(self):
        self.process._RPM(CAMERA_PTR, self.camera)

        self.p1.update()
        self.p2.update()
コード例 #4
0
class GameState:
	def __init__(self, environment):
		self.env = environment
		self.process = self.env.process
		self.p1 = PlayerState(self.env, 1, P1_PTR, P1_TEAM_PTR, P1_HBS)
		self.p2 = PlayerState(self.env, 2, P2_PTR, P2_TEAM_PTR, P2_HBS)
		self.camera = GAME_CAMERA()
	

	def update(self):
		self.process._RPM(CAMERA_PTR, self.camera)

		self.p1.update()
		self.p2.update()
コード例 #5
0
    def run_simulator(self, iterations: int):
        turns = []
        loc_turns = defaultdict(list)
        total_banishers = 0
        total_macros = 0

        for _ in range(iterations):
            player_state = PlayerState(decisions=decisions,
                                       nc_mod=my_non_combat_rate,
                                       item_mod=my_item_drops,
                                       available_macros=total_available_macros)
            player_state.inventory[Items.BloodiedSurgicalDungarees] += 1
            player_state.inventory[Items.SurgicalApron] += 1
            #player_state.inventory[Items.HalfSizeScalpel] += 1
            #player_state.inventory[Items.SurgicalMask] += 1
            #player_state.inventory[Items.HeadMirror] += 1
            self.do_quest(player_state)
            turns.append(player_state.total_turns_spent)
            for loc in player_state.locations:
                banishers_used = player_state.locations[loc].banishers_used
                macros_used = player_state.locations[loc].macros_used
                total_banishers += banishers_used
                total_macros += macros_used
                loc_turns[loc].append(player_state.locations[loc].turns_spent)

        utils.log(
            f"In {iterations} instances at {threshold} max surgeonosity, and an average of {total_banishers / iterations} banishers and {total_macros / iterations} macros, it took an average of {statistics.mean(turns)} turns to complete the Hidden Hopsital, with a median of {statistics.median(turns)} and a deviation of {statistics.pstdev(turns)}."
        )

        for key in loc_turns:
            mean = statistics.mean(loc_turns[key])
            plural = "s" if mean > 1 else ""
            utils.log(f"{key}: {mean} turn{plural}")
コード例 #6
0
    def run_simulator(self, iterations: int):
        turns = []
        loc_turns = defaultdict(list)
        total_banishers = 0
        total_macros = 0

        for _ in range(iterations):
            player_state = PlayerState(decisions=decisions,
                                       nc_mod=my_non_combat_rate,
                                       item_mod=my_item_drops,
                                       available_macros=total_available_macros)
            self.do_quest(player_state)
            turns.append(player_state.total_turns_spent)
            for loc in player_state.locations:
                banishers_used = player_state.locations[loc].banishers_used
                macros_used = player_state.locations[loc].macros_used
                total_banishers += banishers_used
                total_macros += macros_used
                loc_turns[loc].append(player_state.locations[loc].turns_spent)

        utils.log(
            f"In {iterations} instances at {my_non_combat_rate}% +NC and an average of {total_banishers / iterations} banishers and {total_macros / iterations} macros, it took an average of {statistics.mean(turns)} turns to complete the Hidden City quest, with a median of {statistics.median(turns)} and a deviation of {statistics.pstdev(turns)}."
        )

        for key in loc_turns:
            mean = statistics.mean(loc_turns[key])
            plural = "s" if mean > 1 else ""
            utils.log(f"{key}: {mean} turn{plural}")

        utils.log("And 5 turns for location unlocks and defeating the boss.")
コード例 #7
0
ファイル: StateObject.py プロジェクト: trapwired/ZW_Date_bot
 def __init__(self, player_state: PlayerState, _retired: bool = False):
     self.state = PlayerState(player_state)
     self.game_number = -1
     self.spectator_id = -1
     self.retired = _retired
コード例 #8
0
	def __init__(self, environment):
		self.env = environment
		self.process = self.env.process
		self.p1 = PlayerState(self.env, 1, P1_PTR, P1_TEAM_PTR, P1_HBS)
		self.p2 = PlayerState(self.env, 2, P2_PTR, P2_TEAM_PTR, P2_HBS)
		self.camera = GAME_CAMERA()
コード例 #9
0
 def __init__(self, game = None):
     self.controller = Controller()
     self.handle_spritesheet()
     self.state = PlayerState(game)
     self.autsch = pygame.mixer.Sound(os.path.join(pfad, "autsch.ogg"))
     LittleSprite.__init__(self, self.image, game)
コード例 #10
0
class Charactor(LittleSprite, PlayerState):

    images                  = {}
    basename                = "Lupo"
    pose                    = 0
    current_animation_index = 0
    update_interval         = 200
    speed                   = 3
    coords                  = []
    
    def __init__(self, game = None):
        self.controller = Controller()
        self.handle_spritesheet()
        self.state = PlayerState(game)
        self.autsch = pygame.mixer.Sound(os.path.join(pfad, "autsch.ogg"))
        LittleSprite.__init__(self, self.image, game)

    def set_startpos(self, coords=[]):
        self.coords = coords
        self.rect.center = self.coords
        self.movement = [0,0]



    def update(self):
#        print "(update) movement {0}".format(self.movement)
        self.rect         = self.image.get_rect()
        self.rect.topleft = self.coords
        
        if not self.state.alive:
#            print "player not alive"
            return
        
        self.controller.handle_keyboard_input(self)
#        print "controller -> update -> movement {0}".format(self.movement)
        self.state.set_current_state()
        self.state.set_walk_directions()

        self.meanie_collision()
        self.solids_collision()
        self.move_screen_and_player()

        if self.movement[0] != 0:
            self.change_current_animation_index()

        self.coords = self.rect.topleft
        dirty_rect = copy.copy(self.rect)
        dirty_rect = dirty_rect.inflate(16, 16)
        self.game.display.dirty_rects.append(dirty_rect)
        del dirty_rect

        self.game.display.paint_sprite(self)
        

    def handle_spritesheet(self):
        tilewidth  = 24
        tileheight = 32
        spritesheet = "charset-brunnenkletterer-02.png"
        spritesheet = pygame.image.load(os.path.join(pfad , spritesheet)).convert()
        colorkey = spritesheet.get_at([0,0])
        spritesheet.set_colorkey(colorkey)   
        ix, iy = 0, 0
         
        for x in range(0, spritesheet.get_width(), tilewidth):
            iy = 0
            for y in range(0, spritesheet.get_height(), tileheight):
                img = spritesheet.subsurface( [x + 5, y + 10, tilewidth - 5, tileheight - 10] )
                big = pygame.transform.scale2x(img)
                self.images[ix, iy] = big
                iy += 1
            ix += 1
        ## fix fallen player tile
        self.images[3,3] = pygame.transform.scale2x(spritesheet.subsurface(70, 110, 26, 18))
        ## insert gravestone at unused tile
#        grabstein = pygame.image.load(os.path.join(pfad, "grabstein.png"))
#        self.images[0,0] = grabstein
        self.image = self.images[self.current_animation_index, 2]
        self.rect = self.image.get_rect()


    def placeTNT(self):
#        if not self.state.tntOnScreen:
        tntCoords = copy.copy(self.rect)
        tntCoords.centerx -= self.game.display.bgpos[0] 
        tntCoords.centery  -= self.game.display.bgpos[1] - self.rect.height / 2
        if self.state.facing_right:
            tntCoords.centerx += 24
        tnt = TNT(tntCoords)
        self.game.props.add(tnt)
        self.game.allElements.add(tnt)
        self.state.tntOnScreen = True
#        print tnt.on_screen

    def move_screen_and_player(self):
        vspeed = hspeed = self.speed
        dir = self.movement
        player_movable_x = True
        player_movable_y = True
        if self.state.falling:
            vspeed = self.speed * 2
        else:
            vspeed = self.speed
        if dir[0] != 0 and not self.is_in_horizontal_bounds():
            player_movable_x = self.game.display.move_arena_horizontal(dir, hspeed)
        if dir[1] != 0 and not self.is_in_vertical_bounds() and not self.state.jumping:
            player_movable_y = self.game.display.move_arena_vertikal(dir, vspeed)
        elif dir[1] != 0 and not self.is_in_vertical_bounds() and self.state.jumping:
            player_movable_y = True
        if player_movable_x or player_movable_y:
            self.move_player(player_movable_x, player_movable_y)


    def move_player(self, player_movable_x, player_movable_y):
        if self.is_in_upper_half(): 
            self.game.display.move_arena_vertikal([0,-1], 1)
            self.rect.move_ip([0,1])
        if player_movable_x:
            if self.movement[0] > 0 \
            and self.rect.left < self.game.display.arena[0] - self.rect.width :
                self.rect.move_ip(self.movement[0], 0)
            elif self.movement[0] < 0 \
            and self.rect.left > 0 :
                self.rect.move_ip(self.movement[0], 0)

#        print "(move_player) {0}" . format(self.movement)
#        print self.rect.top < self.game.display.arena[1] - self.rect.height, self.movement

        if player_movable_y:
            if self.movement[1] > 0 and self.rect.top < self.game.display.arena[1] - self.rect.height:
                self.rect.move_ip(0, self.movement[1])
            elif self.movement[1] < 0 and self.rect.top > 0:
                self.rect.move_ip(0, self.movement[1])
        
    def feet(self):
        feet = copy.copy(self)
        r = copy.copy(self.rect)
        r.inflate_ip(-24, -40)
        r.move_ip(0, 24)
        feet.rect = r
        return feet

    def middle(self):
        middle = copy.copy(self)
        r = copy.copy(self.rect)
        r.inflate_ip(-12, -24)
        r.move_ip( 0, 0)
        middle.rect = r
        return middle

    def head(self):
        head = copy.copy(self)
        r = copy.copy(self.rect)
        r.inflate_ip(-24, -40)
        r.move_ip( 0, -20)
        head.rect = r
        return head




    def meanie_collision(self):
        self.mask   = pygame.mask.from_surface(self.image)
        collided_list_body = pygame.sprite.spritecollide(
                                                    self,
                                                    self.game.meanies,
                                                    False,
                                                    None
                                                    )

        collided_list_feet = pygame.sprite.spritecollide(
                                                    self.feet(),
                                                    self.game.meanies,
                                                    False,
                                                    None
                                                    )

        if len (collided_list_body) > 0:
            
            for meanie in collided_list_body:

                if meanie in collided_list_feet:

                    if not meanie.state.is_upside_down:
                        meanie.state.change_to_upside_down()
                        meanie.hitpoints -= 1
                    else:
                        
                        if meanie.hit_time < pygame.time.get_ticks():
                            meanie.hitpoints -= 1
                            if meanie.hitpoints <= 0:
                                meanie.kill()
                else:
                    if not meanie.state.is_upside_down:
                        
                        meanie.mask = pygame.mask.from_surface(meanie.image)
                        collision   = pygame.sprite.collide_mask(self, meanie)
                        if collision is not None:  
#                            print "!! charactor is hit !!"
                            self.kill()

                    
        

        
    def solids_collision(self):
        
        collided_list = pygame.sprite.spritecollide(
                                                    self.middle(),
                                                    self.game.solids,
                                                    False,
                                                    None
                                                    )
        
      
        if len (collided_list) > 0:
            
            for barrel in collided_list:

                if barrel.rect.left <= self.rect.left:
                    self.state.cannot_walk_left()
                elif barrel.rect.left >= self.rect.left:
                    self.state.cannot_walk_right()


    def handle_bricklist(self, brick_list):
        hcoords, vcoords = self.coords
        for brick in brick_list:
            vcoords = brick.rect.top - (self.rect.height + 2)
            if hasattr(brick,'alternate_image'):
                if brick.state.set_to_cleared() is True:
                    self.game.level.bricks_total -= 1
        self.coords = hcoords, vcoords
        self.rect.topleft = self.coords

                
    def change_current_animation_index(self):
        
        if self.update_time < pygame.time.get_ticks():
            self.update_time = pygame.time.get_ticks() + self.update_interval
        
            self.current_animation_index += 1
            if self.current_animation_index > 2:
                self.current_animation_index = 0
         
        self.image = pygame.transform.flip(self.images[self.current_animation_index, self.pose], True, False)
        
                
                
    def face_left(self):
        self.pose = FACE_LEFT
        self.state.facing_right = False
        self.state.facing_left  = True
        self.change_current_animation_index()
        
    def face_right(self):
        self.pose = FACE_RIGHT
        self.state.facing_right = True
        self.state.facing_left  = False
        self.change_current_animation_index()
        
    def face_up(self):
        self.pose = FACE_UP
        self.change_current_animation_index()
        
    def face_down(self):
        self.pose = 2
        self.change_current_animation_index()

    def kill(self):
#        print "sprite is dead"
#        self.image = self.images[0,0]
#        self.game.display.paint_sprite(self)
        self.autsch.play()
        deadman = DeadPlayer(self.coords)
        self.state.alive = False
        self.game.allElements.add(deadman)
        pygame.sprite.Sprite.kill(self)

    def spawn(self, startpos):
#        print "respawning player"
        self.image = self.images[2,2]
        self.set_startpos(startpos)
        self.state.alive = True
        self.update()
        self.game.destructables.add(self)
        self.game.allElements.add(self)
コード例 #11
0
def initial_setup_state(df):
    """ Creates the game state for the initial setup phase of the game
    
    Creates the game state for the setup phase of the game, i.e. turn 0.
    During this phase each player places on board his first 2 settlements and 
    2 roads.
    Also returns all chat messages during this phase to save to chatsDF
    
    Parameters
    ----------
    df : pandas dataframe 
        The soclogs in dataframe form, as returned from read_soclog() for tun 0
    
    Returns
    -------
    turn0_game_state : GameState feature vector
        The game state feature vector from the initial set-up phase
    chats0 : a pandas df 
        The chat messages during the setup phase
    """

    # DONE: call methods with specific rows to retrieve the info

    # DONE: call get_board with message SOCBoardLayout to get board and robber
    #     locate row of SOCBoard Layout and call the get_board(SOCBoardLayout)

    # IMPORTANT : Maybe i should only get turn 0 df part

    # NOTE : turn 0 has no labels  (it is not an actual player's turn)

    # locate the SOCBoardLayout message
    board_message = df.loc[df.MessageType == "SOCBoardLayout"]
    # get_board returns tuple (hexLayout, numLayout,robberHex)
    (hexlayout, numlayout, robberHex) = get_board(board_message.Message.item())

    # call get_players to get the players nicknames and ids
    # find SOCSitDown messages
    sitDown_messages = df.loc[df.MessageType == "SOCSitDown"]
    # players is a dictionary key:playernum value:nickname
    players = get_players(sitDown_messages)

    # DONE : get placement of road and settlement
    # find SOCPutPiece messages
    putPiece_messages = df.loc[df.MessageType == "SOCPutPiece"]
    buildings = get_buildings0(putPiece_messages)

    # create players states
    playerstate = []
    for x in range(4):
        playerstate.append(PlayerState(x, players[x]))

    # update playerStates with the buildings of turn 0
    for player in buildings:
        # for all of player's roads
        for road in buildings[player][0]:  # ROAD = 0
            playerstate[player].built_road(road)

        for settlement in buildings[player][1]:  # SETM = 1
            playerstate[player].built_settlement(settlement)

    # create game state
    turn0_game_state = GameState(0, hexlayout, numlayout, hex(robberHex),
                                 playerstate[0], playerstate[1],
                                 playerstate[2], playerstate[3])

    # get the chat messages
    game_txt_messages = df.loc[df.MessageType == "SOCGameTextMsg"]
    chats0 = get_chats0(game_txt_messages)
    return (turn0_game_state, chats0)
コード例 #12
0
 def cloneGameState(self, node):
     return GameState(PlayerState(node.p1.left, node.p1.right),
                      PlayerState(node.p2.left, node.p2.right), node.turn)
コード例 #13
0
# print( "There are {} reachable states".format( len( gt.getAllNodes() ) ) )

# # print the gametree
# gt.printTree()

# player game
# strat = MaxPayoffSearchStrat( 8 )
# initialState = GameState( PlayerState( 1, 1 ), PlayerState( 1, 1 ), 1 )
# game = Game( initialState )
# game.playPlayerGame( strat )

# TODO next: build the tree up from the bottom to get the true values
# TODO: Another genetic strat that learns as it plays against the raw looking forward strat

# AI playing against itself
initialState = GameState(PlayerState(1, 1), PlayerState(1, 1), 1)

# print every _ games
printNum = 1
n = 50  # number of games
depth1 = 9  # edit this between consoles
for depth2 in range(0, 9 + 1):  # 10 total
    totalP1Wins = 0
    totalP2Wins = 0
    totalP1WinTurns = 0
    totalP2WinTurns = 0
    totalP1Splits = 0
    totalP2Splits = 0
    totalP1WinSplits = 0
    totalP2WinSplits = 0
コード例 #14
0
ファイル: Player.py プロジェクト: Marco-Chin/PokerML
 def __log_player_state(self):
     self.player_state_history.append(
         PlayerState(self.stack, self.bet_amount, self.hand, self.in_hand, self.is_dealer))
コード例 #15
0
ファイル: GameState.py プロジェクト: odabugs/kof13-hitboxes
 def __init__(self, environment):
     self.env = environment
     self.process = self.env.process
     self.p1 = PlayerState(self.env, 1, P1_PTR, P1_TEAM_PTR, P1_HBS)
     self.p2 = PlayerState(self.env, 2, P2_PTR, P2_TEAM_PTR, P2_HBS)
     self.camera = GAME_CAMERA()