Rabbit - first implement
This commit is contained in:
parent
8f80df7ce0
commit
dc8e83e6b2
7
main.py
7
main.py
@ -2,15 +2,16 @@ import sys
|
|||||||
import secrets
|
import secrets
|
||||||
|
|
||||||
from src.graphics import *
|
from src.graphics import *
|
||||||
|
from src.rabbit import Rabbit
|
||||||
from src.waiter import *
|
from src.waiter import *
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# SETUP
|
# SETUP
|
||||||
pygame.init()
|
pygame.init()
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
fps = 2
|
|
||||||
graphics = Graphics()
|
graphics = Graphics()
|
||||||
waiter = Waiter(graphics)
|
waiter = Waiter(graphics)
|
||||||
|
rabbit = Rabbit()
|
||||||
|
|
||||||
# init functions
|
# init functions
|
||||||
graphics.drawBackground(waiter.matrix)
|
graphics.drawBackground(waiter.matrix)
|
||||||
@ -19,7 +20,9 @@ if __name__ == "__main__":
|
|||||||
goal = None
|
goal = None
|
||||||
path = ''
|
path = ''
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
|
# rabbit.check(waiter.matrix, waiter.X, waiter.Y)
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
@ -50,4 +53,4 @@ if __name__ == "__main__":
|
|||||||
waiter.travel(nextStep, graphics)
|
waiter.travel(nextStep, graphics)
|
||||||
|
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
clock.tick(fps)
|
clock.tick(graphics.fps)
|
||||||
|
6
resources/simulations/learning_data.txt
Normal file
6
resources/simulations/learning_data.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
0 | price: 0 x: 0 y: 0
|
||||||
|
1 | price: 100 x: 0 y: 0
|
||||||
|
0 | price: 0 x: 1 y: 1
|
||||||
|
1 | price: 100 x: 1 y: 1
|
||||||
|
0 | price: 0 x: 2 y: 1
|
||||||
|
1 | price: 100 x: 2 y: 1
|
@ -5,25 +5,22 @@ class Graphics:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.image = {
|
self.image = {
|
||||||
'floor': pygame.image.load('./../resources/images/floor.jpg'),
|
'floor': pygame.image.load('./../resources/images/floor.jpg'),
|
||||||
#
|
|
||||||
'wall': pygame.image.load('./../resources/images/wall.png'),
|
'wall': pygame.image.load('./../resources/images/wall.png'),
|
||||||
#
|
|
||||||
'bar': pygame.image.load('./../resources/images/table3.png'),
|
'bar': pygame.image.load('./../resources/images/table3.png'),
|
||||||
'bar_floor': pygame.image.load('./../resources/images/waiter-up.png'),
|
'bar_floor': pygame.image.load('./../resources/images/waiter-up.png'),
|
||||||
'table': pygame.image.load('./../resources/images/table3.png'),
|
'table': pygame.image.load('./../resources/images/table3.png'),
|
||||||
|
#
|
||||||
'waiter_N': pygame.image.load('./../resources/images/waiter-up.png'),
|
'waiter_N': pygame.image.load('./../resources/images/waiter-up.png'),
|
||||||
'waiter_S': pygame.image.load('./../resources/images/waiter-down.png'),
|
'waiter_S': pygame.image.load('./../resources/images/waiter-down.png'),
|
||||||
'waiter_E': pygame.image.load('./../resources/images/waiter-right.png'),
|
'waiter_E': pygame.image.load('./../resources/images/waiter-right.png'),
|
||||||
'waiter_W': pygame.image.load('./../resources/images/waiter-left.png'),
|
'waiter_W': pygame.image.load('./../resources/images/waiter-left.png'),
|
||||||
#
|
#
|
||||||
'chair_front': pygame.image.load('./../resources/images/chair-front.png'),
|
'chair_front': pygame.image.load('./../resources/images/chair-front.png'),
|
||||||
#
|
|
||||||
'chair_back': pygame.image.load('./../resources/images/chair-back.png'),
|
'chair_back': pygame.image.load('./../resources/images/chair-back.png'),
|
||||||
#
|
|
||||||
'chair_left': pygame.image.load('./../resources/images/chair-left.png'),
|
'chair_left': pygame.image.load('./../resources/images/chair-left.png'),
|
||||||
#
|
|
||||||
'chair_right': pygame.image.load('./../resources/images/chair-right.png')
|
'chair_right': pygame.image.load('./../resources/images/chair-right.png')
|
||||||
}
|
}
|
||||||
|
self.fps = 2
|
||||||
self.block_size = 50
|
self.block_size = 50
|
||||||
self.height = 15
|
self.height = 15
|
||||||
self.width: int = 14
|
self.width: int = 14
|
||||||
|
@ -44,3 +44,6 @@ class Matrix:
|
|||||||
|
|
||||||
def watch_through(self, x, y):
|
def watch_through(self, x, y):
|
||||||
return self.matrix[x][y].watch_through
|
return self.matrix[x][y].watch_through
|
||||||
|
|
||||||
|
def tile_worth(self, x, y):
|
||||||
|
return self.matrix[x][y].worth
|
20
src/rabbit.py
Normal file
20
src/rabbit.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from vowpalwabbit import pyvw
|
||||||
|
|
||||||
|
|
||||||
|
class Rabbit:
|
||||||
|
def __init__(self):
|
||||||
|
self.data = open('./../resources/simulations/learning_data.txt')
|
||||||
|
self.model = pyvw.vw(quiet=True)
|
||||||
|
self.train_set = self.data.read().splitlines()
|
||||||
|
self.learn()
|
||||||
|
|
||||||
|
def learn(self):
|
||||||
|
for example in self.train_set:
|
||||||
|
self.model.learn(example)
|
||||||
|
|
||||||
|
def check(self, matrix, x, y):
|
||||||
|
set = ["| price:", str(matrix.tile_worth(x, y)), "x:", str(x), "y:", str(y)]
|
||||||
|
test_sample = ' '.join(set)
|
||||||
|
prediction = self.model.predict(test_sample)
|
||||||
|
print(test_sample)
|
||||||
|
print(prediction)
|
@ -23,6 +23,9 @@ class Tile:
|
|||||||
# Dystant do wierzcholka koncowego oszacowany za pomoca funkcji heurystyki H
|
# Dystant do wierzcholka koncowego oszacowany za pomoca funkcji heurystyki H
|
||||||
self.heuristic = 0
|
self.heuristic = 0
|
||||||
|
|
||||||
|
#Atrybuty AI do rozpoznawania wartości pól
|
||||||
|
self.worth = 0
|
||||||
|
|
||||||
# Operator porownywania pol
|
# Operator porownywania pol
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return True if (self.position == other.position) else False
|
return True if (self.position == other.position) else False
|
||||||
|
@ -50,7 +50,7 @@ class Waiter(pygame.sprite.Sprite):
|
|||||||
self.move(1, 0, graphics)
|
self.move(1, 0, graphics)
|
||||||
if self.direction == 'W':
|
if self.direction == 'W':
|
||||||
self.move(-1, 0, graphics)
|
self.move(-1, 0, graphics)
|
||||||
#print(self.X, self.Y)
|
# print(self.X, self.Y)
|
||||||
|
|
||||||
# AStar
|
# AStar
|
||||||
def findPath(self, goal):
|
def findPath(self, goal):
|
||||||
@ -243,5 +243,6 @@ class Waiter(pygame.sprite.Sprite):
|
|||||||
self.update('L', graphics)
|
self.update('L', graphics)
|
||||||
graphics.update(self)
|
graphics.update(self)
|
||||||
|
|
||||||
|
|
||||||
def getTotalCost(tile):
|
def getTotalCost(tile):
|
||||||
return tile.totalCost
|
return tile.totalCost
|
||||||
|
Loading…
Reference in New Issue
Block a user