예제 #1
0
 def setUp(self):
     """ This map can be done in one step.
     #####  01110
     ##@##  01@10
     #####  01110
     """
     self.mine_map = Map(5, 5, [(2, 2)])
예제 #2
0
 def test_move_one_step(self):
     """ This map can be done in one step.
     #####  01110
     ##@##  01@10
     #####  01110
     """
     mine_map = Map(5, 5, mine_pos_list=[(2, 2)])
     game = Game(mine_map)
     state = game._sweep((0, 0))
     self.assertEqual(state, 2)
예제 #3
0
 def test_move_a(self):
     mine_map = Map(3, 4, mine_pos_list=[(0, 0)])
     test_data_cases = [{
         'click_trace': [(0, 1), (1, 0)],
         'state': 1,
         'cur_step': 2
     }, {
         'click_trace': [(0, 1), (1, 0), (1, 1), (1, 2)],
         'state': 2,
         'cur_step': 4
     }]
     for data in test_data_cases:
         game = Game(mine_map)
         self.batch_click(game, data['click_trace'])
         self.assertEqual(game.state, data['state'])
         self.assertEqual(game.cur_step, data['cur_step'])
예제 #4
0
파일: main.py 프로젝트: mattrick/codearena
from settings import Settings
from core import Map, Tile

starting = Tile(0, 0)
my_map = Map(starting)

print my_map.get_staring_tile()

ne = starting.set_neighbor("ne")

print ne

ne2 = ne.set_neighbor("ne")

print ne2

print str(Map.hex_distance(starting, ne2))
예제 #5
0
 def create_from_mine_index_list(height, width, mine_index_list):
     return Map(height, width, ((index // width, index % width)
                                for index in mine_index_list))
예제 #6
0
 def test_near_mine_map(self):
     mine_pos_list = [(2, 5), (3, 2), (1, 3)]
     mine_map = Map(5, 6, mine_pos_list=mine_pos_list)
     for x, y in mine_pos_list:
         self.assertEqual(mine_map.distribute_map[x][y], -1)
예제 #7
0
 def create_map(self, mine_pos_list):
     """convert constructing Map object to a callable function for self.assertRaises statement
     """
     m = Map(self.height, self.width, mine_pos_list)
     return m
예제 #8
0
 def test_mine_valid_pos(self):
     """Test creating map with valid mine position.
     """
     for data in self.valid_pos_data:
         m = Map(self.height, self.width, data['mine_pos_list'])
         self.assertEqual(m.mine_number, data['mine_number'])
예제 #9
0
pygame.init()
win = pygame.display.set_mode((700, 700))

already_dead_ops = set()
start = time.time()
episode_rewards = []
random_liberty = []
len_qtable = []

start_pos = [(15 * 5, 15 * 5), (50 * 10 - 15 * 5, 50 * 10 - 15 * 5),
             (50 * 10 - 15 * 5, 15 * 5), (15 * 5, 50 * 10 - 15 * 5)]

for episode in range(HM_EPISODES):
    #map = Map(MAP_SIZE, win, file='map2.txt')
    map = Map(MAP_SIZE, win)
    p = Player(map.start[0] + 1, map.start[1] + 2, 10, map, 150, win,
               MOVE_PENALTY, DEATH_PENALTY, FOOD_REWARD)

    episode_reward = 0

    if episode % SHOW_EVERY == 0 and SHOW_EVERY > 0:
        show = True
    else:
        show = False
    r = False
    for i in range(EPISODE_TIMEOUT):
        obs = p.get_state()

        action = 0
        if LOAD or np.random.random() > epsilon: