2022-04-11 00:01:57 +02:00
|
|
|
from enum import Enum
|
2022-05-17 22:54:56 +02:00
|
|
|
import torchvision.transforms as transforms
|
|
|
|
import torch
|
2022-04-11 00:01:57 +02:00
|
|
|
|
2022-03-09 16:59:58 +01:00
|
|
|
GAME_TITLE = 'WMICraft'
|
|
|
|
WINDOW_HEIGHT = 800
|
|
|
|
WINDOW_WIDTH = 1360
|
2022-04-10 20:28:50 +02:00
|
|
|
FPS_COUNT = 60
|
2022-04-12 20:21:29 +02:00
|
|
|
TURN_INTERVAL = 300
|
2022-04-10 20:28:50 +02:00
|
|
|
|
2022-03-09 16:59:58 +01:00
|
|
|
GRID_CELL_PADDING = 5
|
2022-04-10 20:28:50 +02:00
|
|
|
GRID_CELL_SIZE = 36
|
2022-03-09 16:59:58 +01:00
|
|
|
ROWS = 19
|
|
|
|
COLUMNS = 24
|
2022-04-10 20:28:50 +02:00
|
|
|
|
2022-03-09 16:59:58 +01:00
|
|
|
BORDER_WIDTH = 10
|
|
|
|
BORDER_RADIUS = 5
|
2022-04-10 20:28:50 +02:00
|
|
|
|
2022-03-21 20:30:02 +01:00
|
|
|
KNIGHTS_SPAWN_WIDTH = 4
|
2022-04-05 10:47:45 +02:00
|
|
|
KNIGHTS_SPAWN_HEIGHT = 7
|
|
|
|
LEFT_KNIGHTS_SPAWN_FIRST_ROW = 6
|
|
|
|
LEFT_KNIGHTS_SPAWN_FIRST_COL = 0
|
|
|
|
RIGHT_KNIGHTS_SPAWN_FIRST_ROW = 6
|
|
|
|
RIGHT_KNIGHTS_SPAWN_FIRST_COL = 20
|
|
|
|
|
2022-03-24 16:32:14 +01:00
|
|
|
CASTLE_SPAWN_WIDTH = 6
|
|
|
|
CASTLE_SPAWN_HEIGHT = 5
|
|
|
|
CASTLE_SPAWN_FIRST_ROW = 7
|
|
|
|
CASTLE_SPAWN_FIRST_COL = 9
|
2022-04-10 20:28:50 +02:00
|
|
|
|
|
|
|
NBR_OF_WATER = 16
|
|
|
|
NBR_OF_TREES = 20
|
|
|
|
NBR_OF_MONSTERS = 2
|
2022-04-13 18:35:02 +02:00
|
|
|
NBR_OF_SANDS = 35
|
2022-04-10 20:28:50 +02:00
|
|
|
|
2022-03-09 16:59:58 +01:00
|
|
|
TILES = [
|
|
|
|
'grass1.png',
|
|
|
|
'grass2.png',
|
|
|
|
'grass3.png',
|
2022-04-10 20:28:50 +02:00
|
|
|
'grass4.png',
|
2022-03-09 16:59:58 +01:00
|
|
|
'sand.png',
|
|
|
|
'water.png',
|
|
|
|
'grass_with_tree.jpg',
|
2022-03-11 19:42:17 +01:00
|
|
|
]
|
2022-04-11 17:51:46 +02:00
|
|
|
|
2022-04-11 00:01:57 +02:00
|
|
|
|
|
|
|
class Direction(Enum):
|
|
|
|
UP = 0
|
|
|
|
RIGHT = 1
|
|
|
|
DOWN = 2
|
|
|
|
LEFT = 3
|
|
|
|
|
2022-04-11 12:00:15 +02:00
|
|
|
def right(self):
|
2022-04-11 00:01:57 +02:00
|
|
|
v = (self.value + 1) % 4
|
|
|
|
return Direction(v)
|
|
|
|
|
2022-04-11 12:00:15 +02:00
|
|
|
def left(self):
|
2022-04-11 00:01:57 +02:00
|
|
|
v = (self.value - 1) % 4
|
|
|
|
return Direction(v)
|
|
|
|
|
|
|
|
|
|
|
|
ACTION = {
|
|
|
|
"rotate_left": -1,
|
|
|
|
"rotate_right": 1,
|
|
|
|
"go": 0,
|
|
|
|
}
|
2022-04-11 17:54:00 +02:00
|
|
|
|
2022-04-28 14:13:59 +02:00
|
|
|
# HEALTH_BAR
|
2022-04-11 17:51:46 +02:00
|
|
|
BAR_ANIMATION_SPEED = 1
|
2022-04-28 14:13:59 +02:00
|
|
|
BAR_WIDTH_MULTIPLIER = 0.9 # (0;1>
|
|
|
|
BAR_HEIGHT_MULTIPLIER = 0.1
|
2022-05-17 22:54:56 +02:00
|
|
|
|
2022-05-18 10:29:05 +02:00
|
|
|
|
2022-05-17 22:54:56 +02:00
|
|
|
#NEURAL_NETWORK
|
|
|
|
learning_rate = 0.001
|
|
|
|
batch_size = 7
|
2022-05-18 15:44:07 +02:00
|
|
|
num_epochs = 100
|
2022-05-17 22:54:56 +02:00
|
|
|
|
2022-05-18 10:29:05 +02:00
|
|
|
device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')
|
2022-05-17 22:54:56 +02:00
|
|
|
classes = ['grass', 'sand', 'tree', 'water']
|
|
|
|
|
|
|
|
setup_photos = transforms.Compose([
|
|
|
|
transforms.Resize(36),
|
|
|
|
transforms.CenterCrop(36),
|
|
|
|
transforms.ToPILImage(),
|
|
|
|
transforms.ToTensor(),
|
|
|
|
transforms.Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5])
|
|
|
|
])
|
|
|
|
|
|
|
|
id_to_class = {i: j for i, j in enumerate(classes)}
|
|
|
|
class_to_id = {value: key for key, value in id_to_class.items()}
|