Getting actions for each tile
This commit is contained in:
parent
37d0084561
commit
538b25c07a
@ -1,3 +1,5 @@
|
||||
from typing import Optional
|
||||
|
||||
import pygame
|
||||
import os
|
||||
from kb import ile_podlac, multi_sasiedzi
|
||||
@ -5,6 +7,7 @@ from tile import Tile
|
||||
from config import TILE_SIZE, FINAL_X, FINAL_Y, START_X, START_Y, STARTING_DIRECTION
|
||||
from collections import deque
|
||||
import heapq
|
||||
from decisiontree import model
|
||||
import random
|
||||
|
||||
class Tractor(pygame.sprite.Sprite):
|
||||
@ -30,6 +33,30 @@ class Tractor(pygame.sprite.Sprite):
|
||||
self.actions = self.recreate_actions(path)
|
||||
self.action_index = 0
|
||||
|
||||
def next_turn(self):
|
||||
data=[]
|
||||
actions=[][16]
|
||||
for i in range(16):
|
||||
for j in range(16):
|
||||
current_tile = self.field.tiles.sprites()[j * 16 + i]
|
||||
x, y = i, j
|
||||
neighbors = self.get_neighbors_types(x, y)
|
||||
water_needed = ile_podlac(current_tile.type, current_tile.faza)[0]['Woda']
|
||||
modifier = multi_sasiedzi(current_tile.type, neighbors)[0]['Mul']
|
||||
|
||||
# Tworzenie obiektu danych dla danego pola
|
||||
data_point = {
|
||||
"tile_type": current_tile.type,
|
||||
"water_level": current_tile.water_level,
|
||||
"plant_stage": current_tile.stage,
|
||||
"neighbor_N": neighbors[0] if len(neighbors) > 0 else None,
|
||||
"neighbor_E": neighbors[1] if len(neighbors) > 1 else None,
|
||||
"neighbor_W": neighbors[2] if len(neighbors) > 2 else None,
|
||||
"neighbor_S": neighbors[3] if len(neighbors) > 3 else None
|
||||
}
|
||||
data.append(data_point)
|
||||
actions[i][j] = model.predict(data_point)[0]
|
||||
return actions
|
||||
|
||||
def draw(self, surface):
|
||||
surface.blit(self.image, self.rect)
|
||||
|
Loading…
Reference in New Issue
Block a user