Beispiel #1
0
 def evaluate_pile(self,pile):
     """
     compute the difference in score if the player were to pick up a
     particular pile.
     """
     cards_new = deepcopy(self.cards)
     for color in pile:
         cards_new[color] += 1
     return (ChromakinGame.score(cards_new, self.game_state['scoring']) 
             - ChromakinGame.score(self.cards, self.game_state['scoring']))
Beispiel #2
0
def start_game(request):
    player_list = []
    for i in range(1,6):
        classname = request.POST['player'+str(i)]
        if classname != 'none':
            p = eval(classname[18:]+'("bot'+str(i)+'")')
            player_list.append(p)
    game = ChromakinGame(player_list,[0,1,3,6,10,15,21])
    game.play()
    log = game.flush_log()
    return render_to_response('game.html',{'log':log})
Beispiel #3
0
def start_game(request):
    import sys
    logger = logging.getLogger('chromakin.custom') 
    # instantiate player objects
    player_list = []
    for i in range(2,6):
        try:
            selected_ai = Player.objects.get(pk=request.POST['player'+str(i)])
        except:
            pass
        else:
            p = sys.modules[selected_ai.module].__dict__[selected_ai.name](selected_ai.name)
            player_list.append(p)
            
    
    human_player = browser.BrowserPlayer('You')
    player_list.insert(0, human_player)
    player_key = str(uuid.uuid4())
    logger.debug('caching player object with key '+player_key)
    cache.set(player_key,human_player,600)
    request.session['player_key'] = player_key
            
    # instantiate game object
    game = ChromakinGame(player_list,[0,1,3,6,10,15,21])
    game.initialize_game()
    
    # generate unique ID
    key = str(uuid.uuid4())
    logger.debug('saving game object with cache key ' + key)
    cache.set(key,game,600)
    request.session['game_key'] = key 
    
    
    if cache.get(key) is None or cache.get(player_key) is None:
        logger.error('failed to verify cache write!')
    game_state = game.get_game_state()
    player_names = [p.name for p in player_list]
    return render_to_response('game.html',{'state':game_state,'player_names':player_names},
                              context_instance=RequestContext(request))