-
Notifications
You must be signed in to change notification settings - Fork 0
/
isaac.py
83 lines (63 loc) · 2.11 KB
/
isaac.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from PushBattle import Game, PLAYER1, PLAYER2, EMPTY, BOARD_SIZE, NUM_PIECES, _torus
import numpy as np
import time
import logging
# Set up logging
logging.basicConfig(filename='test_cases_1.log',
level=logging.INFO, format='%(asctime)s - %(message)s')
def evaluate_runtime(func):
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
elapsed_time = end_time - start_time
logging.info(
f"{func.__name__} - Elapsed time: {elapsed_time:.6f} seconds")
return result
return wrapper
# example function for static checks
@evaluate_runtime
def static_weight(game,
board,
turn_count,
attempt_number,
lastFitness):
# useful variables
current_player = game.current_player
p1_tiles = game.p1_tiles
p2_tiles = game.p2_tiles
output = np.zeros((8, 8))
# add your code here
return output
@evaluate_runtime
def RadialConvolution(game,
board,
turn_count,
attempt_number,
lastFitness):
# useful variables
current_player = game.current_player
p1_tiles = game.p1_tiles
p2_tiles = game.p2_tiles
output = np.zeros((8, 8))
"""
Count enemy tiles in a 5x5 window traversing an 8x8 grid with wrap-around.
Parameters:
grid (numpy.ndarray): 8x8 numpy array representing the game board
player (int): Current player (1 or -1)
Returns:
numpy.ndarray: 8x8 numpy array with counts of enemy tiles in each 5x5 window
"""
enemy = -current_player
output = np.zeros((8, 8), dtype=int)
for center_y in range(8):
for center_x in range(8):
count = 0
for i in range(-2, 3):
for j in range(-2, 3):
y = (center_y + i) % 8
x = (center_x + j) % 8
if grid[y, x] == enemy:
count += 1
output[center_y, center_x] = count
return output