def submit_turn(request, game_id): statsd.incr("event.play_turn") game = get_object_or_404(Game, id=game_id) if not game.viewable(request.user): return forbidden() state = game.deserialize(game.current_state()) variables, coefficients = state['variables'], state['coefficients'] while '' in variables.owned_items: variables.owned_items.remove('') while '' in variables.user_messages: variables.user_messages.remove('') from engine.simple_controller import adjust_submission kwargs = {} for key in request.POST: kwargs[key] = request.POST.get(key) kwargs = adjust_submission(kwargs, variables.names) user_submission = game.user_input.schema().deserialize(kwargs) for key in user_submission: variables[key] = user_submission[key] tc = ChainedRandom() turn = logic.Turn(variables, coefficients, tc) alive, variables = turn.go() del variables.people old_state = game.current_state() new_state = State(name=old_state.name, game=old_state.game) new_state.state = json.dumps(dict( variables=variables, coefficients=coefficients)) new_state.save() if not alive: game.mark_finished() game.save() game.score = game.calculate_score() game.save() return redirect(game.show_game_url())
def submit_turn(request, game_id): game = Game.objects.get(pk=game_id) if not game.viewable(request): return forbidden() state = game.deserialize(game.current_state()) variables, coefficients = state['variables'], state['coefficients'] if '' in variables.owned_items: variables.owned_items.remove('') if '' in variables.user_messages: variables.user_messages.remove('') from engine.simple_controller import adjust_submission kwargs = {} for key in request.POST: kwargs[key] = request.POST.get(key) kwargs = adjust_submission(kwargs, variables.names) user_submission = game.user_input.schema().deserialize(kwargs) for key in user_submission: variables[key] = user_submission[key] from twisterclient import TwisterClient as TC tc = TC(base="http://twister.ccnmtl.columbia.edu/", chain=True) turn = logic.Turn(variables, coefficients, tc) alive, variables = turn.go() del variables.people import json old_state = game.current_state() new_state = State(name=old_state.name, game=old_state.game) new_state.state = json.dumps(dict( variables=variables, coefficients=coefficients)) new_state.save() if not alive: game.mark_finished() game.save() return redirect(game.show_game_url())