Rabbit - first implement

This commit is contained in:
s444427 2020-05-13 09:22:12 +02:00
parent 8f80df7ce0
commit dc8e83e6b2
7 changed files with 41 additions and 8 deletions

View File

@ -2,15 +2,16 @@ import sys
import secrets
from src.graphics import *
from src.rabbit import Rabbit
from src.waiter import *
if __name__ == "__main__":
# SETUP
pygame.init()
clock = pygame.time.Clock()
fps = 2
graphics = Graphics()
waiter = Waiter(graphics)
rabbit = Rabbit()
# init functions
graphics.drawBackground(waiter.matrix)
@ -19,7 +20,9 @@ if __name__ == "__main__":
goal = None
path = ''
while True:
for event in pygame.event.get():
# rabbit.check(waiter.matrix, waiter.X, waiter.Y)
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
@ -50,4 +53,4 @@ if __name__ == "__main__":
waiter.travel(nextStep, graphics)
pygame.display.flip()
clock.tick(fps)
clock.tick(graphics.fps)

View 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

View File

@ -5,25 +5,22 @@ class Graphics:
def __init__(self):
self.image = {
'floor': pygame.image.load('./../resources/images/floor.jpg'),
#
'wall': pygame.image.load('./../resources/images/wall.png'),
#
'bar': pygame.image.load('./../resources/images/table3.png'),
'bar_floor': pygame.image.load('./../resources/images/waiter-up.png'),
'table': pygame.image.load('./../resources/images/table3.png'),
#
'waiter_N': pygame.image.load('./../resources/images/waiter-up.png'),
'waiter_S': pygame.image.load('./../resources/images/waiter-down.png'),
'waiter_E': pygame.image.load('./../resources/images/waiter-right.png'),
'waiter_W': pygame.image.load('./../resources/images/waiter-left.png'),
#
'chair_front': pygame.image.load('./../resources/images/chair-front.png'),
#
'chair_back': pygame.image.load('./../resources/images/chair-back.png'),
#
'chair_left': pygame.image.load('./../resources/images/chair-left.png'),
#
'chair_right': pygame.image.load('./../resources/images/chair-right.png')
}
self.fps = 2
self.block_size = 50
self.height = 15
self.width: int = 14

View File

@ -44,3 +44,6 @@ class Matrix:
def watch_through(self, x, y):
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
View 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)

View File

@ -23,6 +23,9 @@ class Tile:
# Dystant do wierzcholka koncowego oszacowany za pomoca funkcji heurystyki H
self.heuristic = 0
#Atrybuty AI do rozpoznawania wartości pól
self.worth = 0
# Operator porownywania pol
def __eq__(self, other):
return True if (self.position == other.position) else False

View File

@ -50,7 +50,7 @@ class Waiter(pygame.sprite.Sprite):
self.move(1, 0, graphics)
if self.direction == 'W':
self.move(-1, 0, graphics)
#print(self.X, self.Y)
# print(self.X, self.Y)
# AStar
def findPath(self, goal):
@ -243,5 +243,6 @@ class Waiter(pygame.sprite.Sprite):
self.update('L', graphics)
graphics.update(self)
def getTotalCost(tile):
return tile.totalCost