def run_game(trial, diff_level=10): state = (0, 0) i = 1 total_pts = 0 while i <= 13: logger.info("%s,diff %2d, trial %d, turn %d", '=' * 20, diff_level, trial, i) i += 1 roll_left = 2 bigstate = get_state_big_mask(state) roll0 = dice_to_id[roll_dice(5)] logger.info('dice0, %s', id_to_dice[roll0]) kid0 = get_option_by_decoding(bigstate, roll0, roll_left, diff_level) keep0 = id_to_kept[kid0] logger.info('keep0,%s', keep0) roll_left -= 1 roll1 = dice_to_id[merge(keep0, roll_dice(5 - len(keep0)))] logger.info('dice1,%s', id_to_dice[roll1]) kid1 = get_option_by_decoding(bigstate, roll1, roll_left, diff_level) keep1 = id_to_kept[kid1] logger.info('keep1,%s', keep1) roll_left -= 1 roll2 = dice_to_id[merge(keep1, roll_dice(5 - len(keep1)))] logger.info('dice2,%s', id_to_dice[roll2]) act = get_option_by_decoding(bigstate, roll2, roll_left, diff_level) state = get_next_state(state, id_to_dice[roll2], Category.CATEGORY_ID_TO_NAME[act]) pts = eval_points[Category.CATEGORY_ID_TO_NAME[act]][id_to_dice[roll2]] logger.info('choice,%s, earn %f', Category.CATEGORY_ID_TO_NAME[act], pts) total_pts += pts logger.info('this turn: %d, total pts: %d, upper score: %d', pts, total_pts, state[1]) logger.info('state: %s', bin(state[0])) if state[1] == 63: total_pts += 35 logger.info('extra bonus added, total: %s', total_pts) return total_pts
def run_game(trial,diff_level=10): state = (0,0) i=1 total_pts = 0 while i<=13: logger.info("%s,diff %2d, trial %d, turn %d", '='*20, diff_level,trial,i) i+=1 roll_left = 2 bigstate = get_state_big_mask(state) roll0 = dice_to_id[roll_dice(5)] logger.info('dice0, %s', id_to_dice[roll0]) kid0 = get_option_by_decoding(bigstate, roll0, roll_left, diff_level) keep0 = id_to_kept[kid0] logger.info('keep0,%s', keep0) roll_left -= 1 roll1 = dice_to_id[merge(keep0, roll_dice(5-len(keep0)))] logger.info('dice1,%s', id_to_dice[roll1]) kid1 = get_option_by_decoding(bigstate, roll1, roll_left, diff_level) keep1 = id_to_kept[kid1] logger.info('keep1,%s', keep1) roll_left -= 1 roll2 = dice_to_id[merge(keep1, roll_dice(5-len(keep1)))] logger.info('dice2,%s', id_to_dice[roll2]) act = get_option_by_decoding(bigstate, roll2, roll_left, diff_level) state = get_next_state(state, id_to_dice[roll2], Category.CATEGORY_ID_TO_NAME[act]) pts = eval_points[Category.CATEGORY_ID_TO_NAME[act]][id_to_dice[roll2]] logger.info('choice,%s, earn %f', Category.CATEGORY_ID_TO_NAME[act], pts) total_pts += pts logger.info('this turn: %d, total pts: %d, upper score: %d',pts, total_pts, state[1]) logger.info('state: %s', bin(state[0])) if state[1] == 63: total_pts += 35 logger.info( 'extra bonus added, total: %s', total_pts) return total_pts
def run_game_two_players(trial, diff_level=50): """ the first player is the bot player with fixed difficulty level the second player is the adaptive bot that tries to get a final score as close as to the first play's. """ state = (0,0) # first player state my_state = (0,0) # second player state turn = 1 total_pts = 0 my_total_pts = 0 while turn<=13: # first player begin logger.info("%s,diff %2d, trial %d, p1-turn %d", '='*20, diff_level,trial,turn) roll_left = 2 bigstate = get_state_big_mask(state) roll0 = dice_to_id[roll_dice(5)] logger.info('dice0, %s', id_to_dice[roll0]) kid0 = get_option_by_decoding(bigstate, roll0, roll_left, diff_level) keep0 = id_to_kept[kid0] logger.info('keep0,%s', keep0) roll_left -= 1 roll1 = dice_to_id[merge(keep0, roll_dice(5-len(keep0)))] logger.info('dice1,%s', id_to_dice[roll1]) kid1 = get_option_by_decoding(bigstate, roll1, roll_left, diff_level) keep1 = id_to_kept[kid1] logger.info('keep1,%s', keep1) roll_left -= 1 roll2 = dice_to_id[merge(keep1, roll_dice(5-len(keep1)))] logger.info('dice2,%s', id_to_dice[roll2]) act = get_option_by_decoding(bigstate, roll2, roll_left, diff_level) state = get_next_state(state, id_to_dice[roll2], Category.CATEGORY_ID_TO_NAME[act]) pts = eval_points[Category.CATEGORY_ID_TO_NAME[act]][id_to_dice[roll2]] my_diff_level = get_adaptive_diff(turn, my_total_pts - total_pts, diff_level) total_pts += pts logger.info('choice,%s, earn %f, exp-score %f', Category.CATEGORY_ID_TO_NAME[act], pts, total_pts + get_expected_score(state)) logger.info('this turn: %d, total pts: %d, upper score: %d',pts, total_pts, state[1]) logger.info("%s,diff %2d, trial %d, p2-turn %d", '='*20, diff_level,trial,turn) # second player begin # my intelligence is based on delta score and the current turn my_roll_left = 2 my_bigstate = get_state_big_mask(my_state) my_roll0 = dice_to_id[roll_dice(5)] logger.info('dice0, %s', id_to_dice[my_roll0]) my_kid0 = get_option_by_decoding(my_bigstate, my_roll0, my_roll_left, my_diff_level) my_keep0 = id_to_kept[my_kid0] logger.info('keep0,%s', my_keep0) my_roll_left -= 1 my_roll1 = dice_to_id[merge(my_keep0, roll_dice(5-len(my_keep0)))] logger.info('dice1,%s', id_to_dice[my_roll1]) my_kid1 = get_option_by_decoding(my_bigstate, my_roll1, my_roll_left, my_diff_level) my_keep1 = id_to_kept[my_kid1] logger.info('keep1,%s', my_keep1) my_roll_left -= 1 my_roll2 = dice_to_id[merge(my_keep1, roll_dice(5-len(my_keep1)))] logger.info('dice2,%s', id_to_dice[my_roll2]) my_act = get_option_by_decoding(my_bigstate, my_roll2, my_roll_left, my_diff_level) my_state = get_next_state(my_state, id_to_dice[my_roll2], Category.CATEGORY_ID_TO_NAME[my_act]) my_pts = eval_points[Category.CATEGORY_ID_TO_NAME[my_act]][id_to_dice[my_roll2]] my_total_pts += my_pts logger.info('choice,%s, earn %f, exp-score %f', Category.CATEGORY_ID_TO_NAME[my_act], my_pts, my_total_pts + get_expected_score(my_state)) logger.info('this turn: %d, total pts: %d, upper score: %d',my_pts, my_total_pts, my_state[1]) #logger.info('state: %s', bin(state[0])) turn += 1 if state[1] == 63: total_pts += 35 logger.info( 'p1 extra bonus added, total: %s', total_pts) if my_state[1] == 63: my_total_pts += 35 logger.info( 'p2 extra bonus added, total: %s', my_total_pts) return my_total_pts - total_pts
def run_game_two_players(trial, diff_level=50): """ the first player is the bot player with fixed difficulty level the second player is the adaptive bot that tries to get a final score as close as to the first play's. """ state = (0, 0) # first player state my_state = (0, 0) # second player state turn = 1 total_pts = 0 my_total_pts = 0 while turn <= 13: # first player begin logger.info("%s,diff %2d, trial %d, p1-turn %d", '=' * 20, diff_level, trial, turn) roll_left = 2 bigstate = get_state_big_mask(state) roll0 = dice_to_id[roll_dice(5)] logger.info('dice0, %s', id_to_dice[roll0]) kid0 = get_option_by_decoding(bigstate, roll0, roll_left, diff_level) keep0 = id_to_kept[kid0] logger.info('keep0,%s', keep0) roll_left -= 1 roll1 = dice_to_id[merge(keep0, roll_dice(5 - len(keep0)))] logger.info('dice1,%s', id_to_dice[roll1]) kid1 = get_option_by_decoding(bigstate, roll1, roll_left, diff_level) keep1 = id_to_kept[kid1] logger.info('keep1,%s', keep1) roll_left -= 1 roll2 = dice_to_id[merge(keep1, roll_dice(5 - len(keep1)))] logger.info('dice2,%s', id_to_dice[roll2]) act = get_option_by_decoding(bigstate, roll2, roll_left, diff_level) state = get_next_state(state, id_to_dice[roll2], Category.CATEGORY_ID_TO_NAME[act]) pts = eval_points[Category.CATEGORY_ID_TO_NAME[act]][id_to_dice[roll2]] my_diff_level = get_adaptive_diff(turn, my_total_pts - total_pts, diff_level) total_pts += pts logger.info('choice,%s, earn %f, exp-score %f', Category.CATEGORY_ID_TO_NAME[act], pts, total_pts + get_expected_score(state)) logger.info('this turn: %d, total pts: %d, upper score: %d', pts, total_pts, state[1]) logger.info("%s,diff %2d, trial %d, p2-turn %d", '=' * 20, diff_level, trial, turn) # second player begin # my intelligence is based on delta score and the current turn my_roll_left = 2 my_bigstate = get_state_big_mask(my_state) my_roll0 = dice_to_id[roll_dice(5)] logger.info('dice0, %s', id_to_dice[my_roll0]) my_kid0 = get_option_by_decoding(my_bigstate, my_roll0, my_roll_left, my_diff_level) my_keep0 = id_to_kept[my_kid0] logger.info('keep0,%s', my_keep0) my_roll_left -= 1 my_roll1 = dice_to_id[merge(my_keep0, roll_dice(5 - len(my_keep0)))] logger.info('dice1,%s', id_to_dice[my_roll1]) my_kid1 = get_option_by_decoding(my_bigstate, my_roll1, my_roll_left, my_diff_level) my_keep1 = id_to_kept[my_kid1] logger.info('keep1,%s', my_keep1) my_roll_left -= 1 my_roll2 = dice_to_id[merge(my_keep1, roll_dice(5 - len(my_keep1)))] logger.info('dice2,%s', id_to_dice[my_roll2]) my_act = get_option_by_decoding(my_bigstate, my_roll2, my_roll_left, my_diff_level) my_state = get_next_state(my_state, id_to_dice[my_roll2], Category.CATEGORY_ID_TO_NAME[my_act]) my_pts = eval_points[Category.CATEGORY_ID_TO_NAME[my_act]][ id_to_dice[my_roll2]] my_total_pts += my_pts logger.info('choice,%s, earn %f, exp-score %f', Category.CATEGORY_ID_TO_NAME[my_act], my_pts, my_total_pts + get_expected_score(my_state)) logger.info('this turn: %d, total pts: %d, upper score: %d', my_pts, my_total_pts, my_state[1]) #logger.info('state: %s', bin(state[0])) turn += 1 if state[1] == 63: total_pts += 35 logger.info('p1 extra bonus added, total: %s', total_pts) if my_state[1] == 63: my_total_pts += 35 logger.info('p2 extra bonus added, total: %s', my_total_pts) return my_total_pts - total_pts