def simple_model_query_test(): g = Game() hands_int = [B1, B3, B2, G3, R1, B1, B2, R2, R3] hands = [] colors = [0, Color.RED, Color.GREEN, Color.BLUE] for i in range(0, len(hands_int)): hands.append( Card(colors[Card.color_of_card(hands_int[i])], Card.num_of_card(hands_int[i]))) g.board.player_hands = hands model = Model(3, 3, g.board.player_hands) model.graph = nx.MultiGraph() nodes = [ 'B1,B3,B2,G3,R1,B1,B2,R2,R3', # 'B1,B3,B2,G3,R1,B1,B2,R2,R3', # 'B1,B3,B2,G3,R1,B1,B2,R2,R3', 'G1,B3,B2,G3,R1,B1,B2,R2,R3', # 0: G1 'R1,B1,B2,G3,R1,B1,B2,R2,R3', # 0: R1 'B1,B3,B2,G1,R1,B1,B2,R2,R3', # 3: G1 'B1,B3,B2,R1,R1,B1,B2,R2,R3', # 3: R1 'B1,B3,B2,G3,R1,B1,B1,R2,R3', # 6: B1 'B1,B3,B2,G3,R1,B1,R1,R2,R3', # 6: R1 ] node_nums = [] for node in nodes: node_nums.append(','.join( map(lambda x: str(card_dict[x]), node.split(',')))) model.graph.add_nodes_from(node_nums) model.connect_nodes(node_nums[0:3], 0) model.connect_nodes([node_nums[0]] + node_nums[3:5], 1) model.connect_nodes([node_nums[0]] + node_nums[5:7], 2) model.add_self_loops() # x = model.get_player_cliques(0, hands=list(map(int,g.board.player_hands)), worlds=model.graph.nodes) # x = model.get_player_cliques(1, hands=list(map(int,g.board.player_hands)), worlds=model.graph.nodes) # x = model.get_player_cliques(2, hands=list(map(int,g.board.player_hands)), worlds=model.graph.nodes) val = model.query_model( "M0(**,B1,**,G3,R1,B1,B2,R2,R3)", list(map(int, g.board.player_hands))) #|(K2(B1,B3,B2,G3,R1,B1,B2,R2,R3))") # val = model.query_model("K2(B1,B3,B2,G3,R1,B1,B2,R2,R3)") print(val)
def model_query_test(): g = Game() hands_int = [B1, B3, B2, G3, R1, B1, B2, R2, R3] hands = [] colors = [0, Color.RED, Color.GREEN, Color.BLUE] for i in range(0, len(hands_int)): hands.append( Card(colors[Card.color_of_card(hands_int[i])], Card.num_of_card(hands_int[i]))) g.board.player_hands = hands model = Model(3, 3, g.board.player_hands) val = model.query_model("K0(B*,**,**,G3,R1,B1,B2,R2,R3)", list(map(int, g.board.player_hands))) # true print(val)
def main(): # simple_model_query_test() # model_query_test() # model_update_test() # "K0(~p)" agent 0 knows p is false # "~K0(p)" agent 0 doesn't know p is true g = Game() hands_int = [B1, B3, B2, G3, R1, B1, B2, R1, R3] hands = [] colors = [0, Color.RED, Color.GREEN, Color.BLUE] for i in range(0, len(hands_int)): hands.append( Card(colors[Card.color_of_card(hands_int[i])], Card.num_of_card(hands_int[i]))) g.board.player_hands = hands model = Model(3, 3, g.board.player_hands)
def model_update_test(): g = Game() hands_int = [B1, B3, B2, G3, R1, B1, B2, R1, R3] hands = [] colors = [0, Color.RED, Color.GREEN, Color.BLUE] for i in range(0, len(hands_int)): hands.append( Card(colors[Card.color_of_card(hands_int[i])], Card.num_of_card(hands_int[i]))) g.board.player_hands = hands model = Model(3, 3, g.board.player_hands) model.graph = nx.MultiGraph() nodes = [ 'B1,B3,B2,G3,NC,B1,B2,R1,R3', 'G1,B3,B2,G3,NC,B1,B2,R1,R3', # 0: G1 'R1,B3,B2,G3,NC,B1,B2,R1,R3', # 0: R1 'B1,B3,B2,G1,NC,B1,B2,R1,R3', # 3: G1 'B1,B3,B2,R1,NC,B1,B2,R1,R3', # 3: R1 'B1,B3,B2,G3,NC,B1,B1,G1,R3', # 6: B1 'B1,B3,B2,G3,NC,B1,R1,G1,R3', # 6: R1 ] g.board.player_hands[4] = Card(Color.NO_COLOR, -1) node_nums = [] for node in nodes: node_nums.append(','.join( map(lambda x: str(card_dict[x]), node.split(',')))) model.graph.add_nodes_from(node_nums) model.connect_nodes(node_nums[0:3], 0) model.connect_nodes([node_nums[0]] + node_nums[3:5], 1) model.connect_nodes([node_nums[0]] + node_nums[5:7], 2) model.add_self_loops() hand_format = convert_cards_to_node(list(map(int, g.board.player_hands))) print('acc nodes', model.get_accessible_nodes_from_world(2, hand_format)) # print(list(map(int,g.board.player_hands))) # model.get_player_cliques(2,list(map(int,g.board.player_hands))) p_num = 1 card_replaced = 'G3' card_that_replaces = 'R1' hand_index = 0 print(worlds_of_strings(model.graph.nodes)) model.update_discard_and_play(Card(string=card_replaced), player_num=p_num, hand_idx=hand_index, discard_pile=[], stacks=[0, 0, 0], hands=list(map(int, g.board.player_hands))) discard_pile = list( map(int, [Card(string='R1')] * 1 + [Card(string='R2')] * 1 + [Card(string='G1')] * 2 + [Card(string='G2')] * 1 + [Card(string='G3')] * 0 + [Card(string='B1')] * 1 + [Card(string='B2')] * 0 + [Card(string='B3')] * 0)) print(worlds_of_strings(model.graph.nodes)) NUMBER_CLUE = 0 COLOR_CLUE = 1 RED = 1 GREEN = 2 BLUE = 3 # model.update_clue(player_num=2, clue=(COLOR_CLUE,RED), hands=list(map(int,g.board.player_hands))) model.update_draw_card(card=Card(string=card_that_replaces), player_num=p_num, hand_idx=hand_index, discard_pile=discard_pile, stacks=[0, 0, 0], hands=list(map(int, g.board.player_hands))) g.board.player_hands[p_num * self.cards_per_player + hand_index] = Card(string=card_that_replaces) print(worlds_of_strings(model.graph.nodes))