Пример #1
0
def auto_set_numerical(set):
    from paigow.pghand import PGHand

    if PGStrategyLogging.logging:
        print "\nauto_set_numerical BEGIN"

    picked_ordering = None

    # create sets with the three possible combinations.  We'll be re-arranging
    # one of these to create sets so make them editable lists.
    tiles = set.tiles
    if PGStrategyLogging.logging:
        print " ... tiles: [ " + tiles[0].name + ", " + tiles[
            1].name + ", " + tiles[2].name + ", " + tiles[3].name + " ]"
    tiles1 = [tiles[0], tiles[1], tiles[2], tiles[3]]
    tiles2 = [tiles[0], tiles[2], tiles[1], tiles[3]]
    tiles3 = [tiles[0], tiles[3], tiles[1], tiles[2]]
    sets = (None, PGSet.create(tiles1), PGSet.create(tiles2),
            PGSet.create(tiles3))
    ordering = picked_ordering_for_sets(sets)

    # we founds something, re-order the tiles for it.
    if ordering > 0:
        reorder_hands_for_setting(set, ordering)
    else:
        print "WTF? auto_sort didn't find anything?"

    return ordering
Пример #2
0
def auto_set_numerical( set ):
  from paigow.pghand import PGHand
  
  if PGStrategyLogging.logging:
    print "\nauto_set_numerical BEGIN"
  
  picked_ordering = None
  
  # create sets with the three possible combinations.  We'll be re-arranging
  # one of these to create sets so make them editable lists.
  tiles = set.tiles
  if PGStrategyLogging.logging:
    print " ... tiles: [ " + tiles[0].name + ", " + tiles[1].name + ", " + tiles[2].name + ", " + tiles[3].name + " ]"
  tiles1 = [ tiles[0], tiles[1], tiles[2], tiles[3] ]
  tiles2 = [ tiles[0], tiles[2], tiles[1], tiles[3] ]
  tiles3 = [ tiles[0], tiles[3], tiles[1], tiles[2] ]
  sets = ( None, PGSet.create( tiles1 ), PGSet.create( tiles2 ), PGSet.create( tiles3 ) )
  ordering = picked_ordering_for_sets( sets )
  
  # we founds something, re-order the tiles for it.
  if ordering > 0:
    reorder_hands_for_setting( set, ordering )
  else:
    print "WTF? auto_sort didn't find anything?"
  
  return ordering
Пример #3
0
    def assure_player_in_deal(self, player, deal_number):
        from pgplayerindeal import PGPlayerInDeal
        from paigow.pgset import PGSet
        from paigow.pgstrategy import PGStrategy

        pgpid_player = self.player_in_deal(player, deal_number)

        if not pgpid_player:
            # print "cannot find player " + str(player) + "in game " + str(self) + ", creating"
            is_second_player = len(self.players_in_deal(deal_number)) > 0
            # print "... is second player: " + str(is_second_player)
            pgpid_player = PGPlayerInDeal.create(self, player, deal_number)
            pgpid_player.save()  # so self.players() will find it.

            # TBD: remove assumption that there are only two players.  This
            # decides whether this player gets the first set of tiles or the
            # second set of tiles.
            index = 0
            if (is_second_player):
                index = 1

            # Create the hands and fill them.
            deal = self.deal(deal_number)
            sets = []
            for i in range(3):
                set = PGSet.create([
                    deal.tile(index),
                    deal.tile(index + 2),
                    deal.tile(index + 4),
                    deal.tile(index + 6),
                ])
                #from paigow.pgstrategy import auto_set_numerical
                #auto_set_numerical(set)
                sets.append(set)
                index += 8

            # if the player is a computer, then set the tiles.
            if player.name == "computer":
                sets = PGStrategy.auto_set(sets)

            # remember what hands were dealt; when it comes time for
            # the player to say how they set, we want to verify that
            # they didn't cheat ;)
            pgpid_player.set_dealt_sets(sets)

            # remember this player is here, needs to be done before player_is_ready
            pgpid_player.save()

            # the computer is done right away, always.
            if player.name == "computer":
                pgpid_player.player_is_ready(sets[0].tile_chars(),
                                             sets[1].tile_chars(),
                                             sets[2].tile_chars())
                pgpid_player.save()

        return pgpid_player
Пример #4
0
 def assure_player_in_deal( self, player, deal_number ):
   from pgplayerindeal import PGPlayerInDeal
   from paigow.pgset import PGSet
   from paigow.pgstrategy import PGStrategy
   
   pgpid_player = self.player_in_deal( player, deal_number )
   
   if not pgpid_player:
     # print "cannot find player " + str(player) + "in game " + str(self) + ", creating"
     is_second_player = len(self.players_in_deal( deal_number )) > 0
     # print "... is second player: " + str(is_second_player)
     pgpid_player = PGPlayerInDeal.create(  self, player, deal_number )
     pgpid_player.save()   # so self.players() will find it.
     
     # TBD: remove assumption that there are only two players.  This
     # decides whether this player gets the first set of tiles or the
     # second set of tiles.
     index = 0
     if ( is_second_player ):
       index = 1
     
     # Create the hands and fill them.
     deal = self.deal( deal_number )
     sets = []
     for i in range(3):
       set = PGSet.create( [ deal.tile( index ),
                             deal.tile( index + 2 ),
                             deal.tile( index + 4 ),
                             deal.tile( index + 6 ),
                           ]
                         )
       #from paigow.pgstrategy import auto_set_numerical
       #auto_set_numerical(set)
       sets.append( set )
       index += 8
     
     # if the player is a computer, then set the tiles.
     if player.name == "computer":
       sets = PGStrategy.auto_set( sets )
     
     # remember what hands were dealt; when it comes time for
     # the player to say how they set, we want to verify that
     # they didn't cheat ;)
     pgpid_player.set_dealt_sets( sets )
     
     # remember this player is here, needs to be done before player_is_ready
     pgpid_player.save()
     
     # the computer is done right away, always.
     if player.name == "computer":
       pgpid_player.player_is_ready( sets[0].tile_chars(), sets[1].tile_chars(), sets[2].tile_chars() )
       pgpid_player.save()
   
   return pgpid_player
Пример #5
0
def ordering_for_special_hands(set):
    if PGStrategyLogging.logging:
        print "\norder for set " + str(set)

    # we'll be moving tiles around; create a temp set.
    loc_set = PGSet.create(set.tiles)

    # always use two pairs
    ordering = loc_set.ordering_with_two_pair()
    if PGStrategyLogging.logging:
        print "   order for two pairs " + str(ordering)
    if ordering:
        return ordering

    # if we have a pair, there are exceptions
    ordering = loc_set.ordering_with_pair()
    if PGStrategyLogging.logging:
        print "   order for one pairs " + str(ordering)
    if ordering:
        switch_it = False

        # get the tile with the pair
        reorder_hands_for_setting(loc_set, ordering)
        pair_tile = loc_set.tiles[0]

        # we never split pairs of 4s, 5s, 10s or 11s
        if pair_tile.tile_value == 4 or \
           pair_tile.tile_value == 5 or \
           pair_tile.tile_value == 10 or \
           pair_tile.tile_value == 11:
            return ordering

        # we split teens/days if the other two tiles are both seven or higher
        # TBD: would we really want this in the 3-hand, with 8/9?
        #      Teen-bo/seven seems a safer bet than wong/gong
        if pair_tile.is_teen_or_day() and last_two_tiles_are_in(
                set, (7, 8, 9)):
            switch_it = True

        # we split nines if the other two are
        # both within (ten, teen, day)
        elif pair_tile.tile_value == 9 and last_two_tiles_are_in(
                set, (2, 12, 10)):
            switch_it = True

        # we split eights if the other two are
        # both within (elevens, teen, day)
        elif pair_tile.tile_value == 8 and last_two_tiles_are_in(
                set, (2, 12, 11)):
            switch_it = True

        # we split sixes and sevens if the other two are teen/day
        elif (pair_tile.tile_value == 7 or pair_tile.tile_value
              == 6) and last_two_tiles_are_in(set, (2, 12)):
            switch_it = True

        # we split gee joon if the other two are in (five, six) or (teen, day)
        # note we don't want to split them if one is five/six and the other is teen/day;
        # only if both are five/six or both are teen/day.
        elif pair_tile.tile_value == 3 and \
            ( last_two_tiles_are_in( set, ( 2, 12 ) ) or last_two_tiles_are_in( set, ( 5, 6 ) ) ):
            switch_it = True

        # if the ordering was 1, then the first two or the last
        # two are the pair, and we can just switch the middle
        # two tiles (ordering <-- 2).  If the ordering was 2 or three,
        # then the pair wasn't already there, so we use the
        # tiles in their original order (ordering <-- 1).  We can
        # tell by the ordering: if it's 1, then the first two and
        # last two are pairs.
        if switch_it:
            if ordering == 1:
                ordering = 2
            else:
                ordering = 1

    return ordering
Пример #6
0
def ordering_for_special_hands( set ):
  if PGStrategyLogging.logging:
    print "\norder for set " + str(set)

  # we'll be moving tiles around; create a temp set.
  loc_set = PGSet.create( set.tiles )
  
  # always use two pairs
  ordering = loc_set.ordering_with_two_pair()
  if PGStrategyLogging.logging:
    print "   order for two pairs " + str(ordering)
  if ordering:
    return ordering
  
  # if we have a pair, there are exceptions
  ordering = loc_set.ordering_with_pair()
  if PGStrategyLogging.logging:
    print "   order for one pairs " + str(ordering)
  if ordering:
    switch_it = False

    # get the tile with the pair
    reorder_hands_for_setting( loc_set, ordering )
    pair_tile = loc_set.tiles[0]
    
    # we never split pairs of 4s, 5s, 10s or 11s
    if pair_tile.tile_value == 4 or \
       pair_tile.tile_value == 5 or \
       pair_tile.tile_value == 10 or \
       pair_tile.tile_value == 11:
      return ordering
    
    # we split teens/days if the other two tiles are both seven or higher
    # TBD: would we really want this in the 3-hand, with 8/9?
    #      Teen-bo/seven seems a safer bet than wong/gong
    if pair_tile.is_teen_or_day() and last_two_tiles_are_in( set, ( 7, 8, 9 ) ):
      switch_it = True
    
    # we split nines if the other two are
    # both within (ten, teen, day)
    elif pair_tile.tile_value == 9 and last_two_tiles_are_in( set, ( 2, 12, 10 ) ):
      switch_it = True
      
    # we split eights if the other two are
    # both within (elevens, teen, day)
    elif pair_tile.tile_value == 8 and last_two_tiles_are_in( set, ( 2, 12, 11 ) ):
      switch_it = True
    
    # we split sixes and sevens if the other two are teen/day
    elif (pair_tile.tile_value == 7 or pair_tile.tile_value == 6) and last_two_tiles_are_in( set, ( 2, 12 ) ):
      switch_it = True
    
    # we split gee joon if the other two are in (five, six) or (teen, day)
    # note we don't want to split them if one is five/six and the other is teen/day;
    # only if both are five/six or both are teen/day.
    elif pair_tile.tile_value == 3 and \
        ( last_two_tiles_are_in( set, ( 2, 12 ) ) or last_two_tiles_are_in( set, ( 5, 6 ) ) ):
      switch_it = True
    
    # if the ordering was 1, then the first two or the last
    # two are the pair, and we can just switch the middle
    # two tiles (ordering <-- 2).  If the ordering was 2 or three,
    # then the pair wasn't already there, so we use the
    # tiles in their original order (ordering <-- 1).  We can
    # tell by the ordering: if it's 1, then the first two and
    # last two are pairs.
    if switch_it:
      if ordering == 1:
        ordering = 2
      else:
        ordering = 1
  
  return ordering