jer_test #1
41
data/Game.py
41
data/Game.py
@ -1,32 +1,37 @@
|
|||||||
|
from data import Direction
|
||||||
from data.CATEGORY import CATEGORY
|
from data.CATEGORY import CATEGORY
|
||||||
from data.Item import Item
|
from data.Item import Item
|
||||||
from data.Order import Order
|
from data.Order import Order
|
||||||
|
from typing import Dict
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
def __init__(self, id: int, agentPos: (int, int), deliveryPos: (int, int), orderPos: (int,int), stockPilePos: [(int,int)],
|
def __init__(self, id: int, agentPos: (int, int), agentDirection: Direction, deliveryPos: (int, int), orderPos: (int,int), stockPilePos: Dict,
|
||||||
deliveryItem: Item, agentHandId: int, orderStock:[id], orderList: [Order] ):
|
deliveryItem: Item, carriedItem: Item, orderStock: Dict, orderList: [Order]):
|
||||||
|
self.agentDirection = agentDirection
|
||||||
self.id = id
|
self.id = id
|
||||||
self.agentPos = agentPos
|
self.agentPos = agentPos
|
||||||
self.deliveryPos = deliveryPos
|
self.deliveryPos = deliveryPos
|
||||||
self.orderPos = orderPos
|
self.orderPos = orderPos
|
||||||
self.stockPilePos = stockPilePos
|
self.stockPilePos = stockPilePos
|
||||||
self.deliveryItem = deliveryItem
|
self.deliveryItem = deliveryItem
|
||||||
self.agentHandId = agentHandId
|
self.carriedItem = carriedItem
|
||||||
self.orderStock = orderStock
|
self.orderStock = orderStock
|
||||||
self.orderList = orderList
|
self.orderList = orderList
|
||||||
|
|
||||||
def move(self, x: int, y:int):
|
def getCopy(self):
|
||||||
self.agentPos = (x, y)
|
newGame = Game(self)
|
||||||
|
return newGame
|
||||||
def pickUp(self, item: Item):
|
# def move(self, x: int, y: int):
|
||||||
self.deliveryItem = item
|
# self.agentPos = (x, y)
|
||||||
|
#
|
||||||
def drop(self, item: Item):
|
# def pickUp(self, item: Item):
|
||||||
self.deliveryItem = -1
|
# self.deliveryItem = item
|
||||||
|
#
|
||||||
def identify(item: Item, category: CATEGORY):
|
# def drop(self, item: Item):
|
||||||
item.category = category
|
# self.deliveryItem = -1
|
||||||
|
#
|
||||||
def finishOrder(order: Order):
|
# def identify(item: Item, category: CATEGORY):
|
||||||
order.id = -1
|
# item.category = category
|
||||||
|
#
|
||||||
|
# def finishOrder(order: Order):
|
||||||
|
# order.id = -1
|
108
test/nastepnik.py
Normal file
108
test/nastepnik.py
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
from enum import Enum
|
||||||
|
from typing import Tuple, Dict
|
||||||
|
|
||||||
|
from data import Game, Direction
|
||||||
|
|
||||||
|
def getHotSpot(game:Game) -> (int, int):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def isOrderReady(game:Game) -> bool:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def getReadyOrderId(game:Game) -> int:
|
||||||
|
pass
|
||||||
|
|
||||||
|
class Action():
|
||||||
|
|
||||||
|
|
||||||
|
def __init__(self, game: Game):
|
||||||
|
self.game = Game
|
||||||
|
|
||||||
|
def rotate(self, direction: Direction) -> Game:
|
||||||
|
self.game.agentDirection = direction
|
||||||
|
pass
|
||||||
|
|
||||||
|
def move(self) -> Game:
|
||||||
|
# w zaleznosci od kierunku napierdala do przodu
|
||||||
|
pass
|
||||||
|
|
||||||
|
def special(self) -> Game:
|
||||||
|
# w zaleznosci od miejsca gdzie jest i czy ma cos na lapie odklada albo bierze przedmiot
|
||||||
|
pass
|
||||||
|
|
||||||
|
def orderOut(self, orderId: int) -> Game:
|
||||||
|
# nalicza punkty wypierdalaorder i czysci orderStock
|
||||||
|
pass
|
||||||
|
|
||||||
|
def heuristic(a: Tuple[int, int], b: Tuple[int, int]) -> float:
|
||||||
|
(x1, y1) = a
|
||||||
|
|
||||||
|
(x2, y2) = b
|
||||||
|
return abs(x1 - x2) + abs(y1 - y2)
|
||||||
|
|
||||||
|
class PossibleMoves(Enum):
|
||||||
|
rotateTop = 1
|
||||||
|
rotateLeft = 2
|
||||||
|
rotateDown = 3
|
||||||
|
rotateRight = 4
|
||||||
|
move = 5
|
||||||
|
|
||||||
|
def getRotationEvaluation(direction: Direction):
|
||||||
|
# get evaluationForMoveAfterRotation
|
||||||
|
return 1.0
|
||||||
|
|
||||||
|
def evaluateMoves(game: Game) -> Dict:
|
||||||
|
posibleMoves = Dict
|
||||||
|
currPos = game.agentPos
|
||||||
|
gameCopy = game.getCopy()
|
||||||
|
getRotationEvaluation()
|
||||||
|
posibleMoves[PossibleMoves.move] = heuristic(currPos, Action(gameCopy).move().agentPos)
|
||||||
|
posibleMoves[PossibleMoves.rotateTop] = getRotationEvaluation(Direction.Direction.top)
|
||||||
|
posibleMoves[PossibleMoves.rotateLeft] = getRotationEvaluation(Direction.Direction.left)
|
||||||
|
posibleMoves[PossibleMoves.rotateDown] = getRotationEvaluation(Direction.Direction.down)
|
||||||
|
posibleMoves[PossibleMoves.rotateRight] = getRotationEvaluation(Direction.Direction.right)
|
||||||
|
return posibleMoves
|
||||||
|
|
||||||
|
def getIndex(value: float, dict: Dict) -> PossibleMoves:
|
||||||
|
for key, val in dict:
|
||||||
|
if val == value:
|
||||||
|
return key
|
||||||
|
|
||||||
|
def getMaxFromList(list: [float]) -> float:
|
||||||
|
maxi = -10000000
|
||||||
|
for i in range(len(list)):
|
||||||
|
if list[i] > maxi:
|
||||||
|
maxi = list[i]
|
||||||
|
|
||||||
|
return maxi
|
||||||
|
|
||||||
|
def getBestPossibleMove(game: Game) -> PossibleMoves:
|
||||||
|
movesDict = evaluateMoves()
|
||||||
|
bestChoice = getMaxFromList(movesDict.values())
|
||||||
|
return getIndex(bestChoice, movesDict)
|
||||||
|
|
||||||
|
def getBestMove(game: Game) -> Game:
|
||||||
|
gameCopy = game.getCopy()
|
||||||
|
bestPossibleMove = getBestPossibleMove(gameCopy)
|
||||||
|
|
||||||
|
if bestPossibleMove == PossibleMoves.move:
|
||||||
|
return Action(gameCopy).move()
|
||||||
|
elif bestPossibleMove == PossibleMoves.rotateTop:
|
||||||
|
return Action(gameCopy).rotate(Direction.Direction.top)
|
||||||
|
elif bestPossibleMove == PossibleMoves.rotateLeft:
|
||||||
|
return Action(gameCopy).rotate(Direction.Direction.left)
|
||||||
|
elif bestPossibleMove == PossibleMoves.rotateDown:
|
||||||
|
return Action(gameCopy).rotate(Direction.Direction.down)
|
||||||
|
else:
|
||||||
|
return Action(gameCopy).rotate(Direction.Direction.right)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def nastepnik(game: Game) -> Game:
|
||||||
|
if isOrderReady(game) > -1:
|
||||||
|
return Action(game.getCopy()).orderOut(getReadyOrderId(game))
|
||||||
|
elif game.agentPos == getHotSpot(game):
|
||||||
|
return Action(game.getCopy()).special()
|
||||||
|
else:
|
||||||
|
return getBestMove(game)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user