def main(): p1 = Player(name="John") p2 = Player(name="Hulio") b = Board() b.add_player(p1) b.add_player(p2) b.start() _pprint(filled_cells(b.state)) raw_input() destruct_status = False prev_check = [] state = b.state promotions = 0 while state not in ("FIN", ): # for player in (p1, p2): # b.get_state(player) event = smart_event_factory(state, colors, destruct_status, prev_check) color = 'white' if 'w' == event["name"][0] else 'black' if check_the_turn(event, state) == False: continue else: print "VALID" if "promoted" in event.keys() and event["promoted"]: promotions +=1 print "PROMOTED CHECKS: ", promotions state = check_the_game_state(state, event, colors) if event['cutDown'] and destruction_is_possible(event['finalPos'], filled_cells(state, color=colors[1]), filled_cells(state, color=colors[0]), event.get('promoted')): destruct_status = True prev_check = event['finalPos'] print 'NEXT DESTRUCT' raw_input() else: colors.reverse() destruct_status = False prev_check = [] print 'COLORS REVERSED!' print 'FILLED CELLS: ' , len((filled_cells(state))) raw_input()
# let us check that situation return simple_turn_is_valid(turn_info, game_state, color) # here player about to hit another player else: return turn_with_destruction_is_valid(turn_info, game_state, color) def check_the_game_state(game_state, turn_info, colors): """ Check if change of game state is possible """ parsed_game_state = game_state name = turn_info["name"][1] parsed_game_state["board"][colors[0]][name]["position"] = turn_info["finalPos"] if turn_info["cutDown"]: parsed_game_state["board"][colors[1]][turn_info["cutDown"][0]]["status"] = "dead" print "DEAD: ", parsed_game_state["board"][colors[1]][turn_info["cutDown"][0]] if "promoted" in turn_info.keys() and turn_info["promoted"]: parsed_game_state["board"][colors[0]][name]["promoted"] = 1 if parsed_game_state == game_state: return parsed_game_state else: return False if __name__ == "__main__": from initial import START as state from generators import smart_event_factory event = smart_event_factory(state) print event print check_the_turn(event, state)