Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite track, fuel and new design #471

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
90d7b99
liad_master_optimize
Liad-Golan Aug 7, 2023
36d5ec0
master + optimize way
Liad-Golan Aug 7, 2023
013871a
delete
Liad-Golan Aug 7, 2023
0b98bfe
master + optimize way
Liad-Golan Aug 7, 2023
416521d
master + optimize way
Liad-Golan Aug 8, 2023
41bc27b
master + optimize way
Liad-Golan Aug 8, 2023
c7f3d94
score to gas
Liad-Golan Aug 9, 2023
c97ddef
score to gas
Liad-Golan Aug 9, 2023
a880567
score to gas
Liad-Golan Aug 9, 2023
c008323
score to gas
Liad-Golan Aug 9, 2023
0607064
score to gas
Liad-Golan Aug 9, 2023
eb03b16
score to gas
Liad-Golan Aug 9, 2023
c51d8c5
score to gas
Liad-Golan Aug 9, 2023
431528f
score to gas
Liad-Golan Aug 9, 2023
41dd034
score to gas
Liad-Golan Aug 9, 2023
e159a29
score to gas
Liad-Golan Aug 9, 2023
dd93512
score to gas
Liad-Golan Aug 9, 2023
94c854f
score to gas
Liad-Golan Aug 9, 2023
26c18d1
score to gas
Liad-Golan Aug 9, 2023
c763b6d
score to gas
Liad-Golan Aug 9, 2023
b8d1288
score to gas
Liad-Golan Aug 9, 2023
535bc12
time goes up, you die from 0 score
ItayTheGoat Aug 9, 2023
387549f
score to gas
Liad-Golan Aug 9, 2023
a75a896
score to gas
Liad-Golan Aug 9, 2023
c9fadcb
score to gas
Liad-Golan Aug 9, 2023
7f027cf
score to gas
Liad-Golan Aug 9, 2023
f64d5ad
score to gas
Liad-Golan Aug 9, 2023
05614fa
score to gas
Liad-Golan Aug 9, 2023
a3b112b
score to gas
Liad-Golan Aug 9, 2023
5534d42
score to gas
Liad-Golan Aug 9, 2023
ad9bae0
score to gas
Liad-Golan Aug 9, 2023
63164ed
score to gas
Liad-Golan Aug 9, 2023
4354e34
score to gas
Liad-Golan Aug 9, 2023
96f5d69
score to gas
Liad-Golan Aug 9, 2023
41778fe
score to gas
Liad-Golan Aug 9, 2023
69a80f3
score to gas
Liad-Golan Aug 9, 2023
5edf088
score to gas
Liad-Golan Aug 9, 2023
d244595
score to gas
Liad-Golan Aug 9, 2023
0a5960c
score to gas
Liad-Golan Aug 9, 2023
062f34e
score to gas
Liad-Golan Aug 9, 2023
bbed973
score to gas
Liad-Golan Aug 9, 2023
d909d23
score to gas
Liad-Golan Aug 9, 2023
a1b3815
score to gas
Liad-Golan Aug 9, 2023
efee571
score to gas
Liad-Golan Aug 9, 2023
5c61411
added textures
AmirEitan1 Aug 10, 2023
bdb4bed
added bg textures
AmirEitan1 Aug 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 200 additions & 0 deletions mydriver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
"""
This driver does not do any action.
"""
from rose.common import obstacles, actions # NOQA

driver_name = "test"

find2 = True
goal = False
GoodList = [obstacles.PENGUIN,obstacles.CRACK,obstacles.WATER] #obstacles that earn points
ActionList = [actions.LEFT,actions.NONE,actions.RIGHT]
def worthcheck(world):
return False


def drive(world):
global find2
global home
vision = []
if find2:
find2 = False
home = (world.car.x, world.car.y)
pos = (world.car.x, world.car.y)
#print(pos) #initial - x(1,4),y(6)
# "scans"
# for i in range(1, 4): # i = line we're checking
# list = []
# for j in range(1 + 2 * (i)): # j = square in line we're cheking
# if (pos[0] - i + j > 0) and (pos[0] - i + j < 5):
# list.append(world.get(pos[0] - i + j, pos[1] - i))
# else:
# list.append("B")
# vision.append(list) # vision = list of all the obstacles in front of us

for i in range(1, 4):
list = []
for j in range(3):
num = (pos[0] + j - 1, pos[1] - i)
if num[0] < 0 or num[0] > 5:
list.append('B')
else:
list.append(world.get(num))
vision.append(list)
#print(vision)


# add a worthy path finder

worth = worthcheck(world)
if worth:
pass
else: # what to do if there isn't a worthy prize in sight(deafult)
# point greedy
print(vision)
if vision[0][1] == obstacles.PENGUIN:
return actions.PICKUP
if vision[0][1] == obstacles.CRACK:
return actions.JUMP
if vision[0][1] == obstacles.WATER:
return actions.BRAKE
#obsitcale in front in the car
if vision[0][1] != obstacles.NONE: #front of the car
action = findTheHighScoreWay(vision, pos)
# if vision[0][0] == obstacles.NONE or vision[0][0] == obstacles.PENGUIN:
# print ('There is an obstacle ahead - turning left')
# return actions.LEFT
# elif vision[0][2] == obstacles.NONE or vision[0][2] == obstacles.PENGUIN:
# print('There is an obstacle ahead - turning left')
# return actions.RIGHT
return findTheHighScoreWay(vision, pos)
# if (vision[0][0] != obstacles.NONE and vision[0][0] != obstacles.PENGUIN) and (
# vision[0][2] != obstacles.NONE and vision[0][2] != obstacles.PENGUIN):
# return actions.NONE
""""
best = -1
obst = None
found = False
for i in range(3):
for cur in GoodList:
if vision[1][i + 1] == cur and (
vision[0][i] == obstacles.NONE or vision[0][i] == obstacles.PENGUIN):
found = True
best = i
obst = cur
if cur == GoodList[0]:
return ActionList[i]
break
if found:
break
st = 0
fin = 4
act = [actions.LEFT, actions.NONE, actions.RIGHT]
if (vision[0][0] != obstacles.PENGUIN and vision[0][0] != obstacles.NONE):
st = 1
act.remove(actions.LEFT)
elif (vision[0][2] != obstacles.PENGUIN and vision[0][2] != obstacles.NONE):
fin = 3
act.remove(actions.RIGHT)
for i in range(st, fin):
for cur in GoodList:
if obst != None:
if GoodList.index(obst) <= GoodList.index(cur):
break
if vision[2][2 + i] == cur and (
vision[1][i + 1] == obstacles.NONE or vision[1][i + 1] == obstacles.PENGUIN):
if i <= (fin + st / 2):
return act[0]
else:
return act[-1]
if best != -1:
return ActionList[best]
# what he does if there is an obstacle in front of him.
if vision[0][1] != obstacles.NONE:
if vision[0][0] == obstacles.NONE:
return actions.LEFT
elif vision[0][2] == obstacles.NONE:
return actions.RIGHT
# else.
if pos[0] < home[0] and vision[0][2] == obstacles.NONE:
return actions.RIGHT
if pos[0] > home[0] and vision[0][0] == obstacles.NONE:
return actions.LEFT
"""
return actions.NONE


def sumScore(line):
penguin = 10
crack = 5
water = 4
sumTotal = 0

for spot in line:
if spot == obstacles.PENGUIN and (line.index(spot) != 0 or line[3] == 'front'):
sumTotal += penguin
print('pinguin - spot = ', spot, 'lines', line)
elif spot == obstacles.CRACK and (line.index(spot) != 0 or line[3] == 'front'):
sumTotal += crack
print('crack - spot = ', spot, 'lines', line)
elif spot == obstacles.WATER and (line.index(spot) != 0 or line[3] == 'front'):
sumTotal += water
print('water - spot = ', spot, 'lines', line)
elif spot == obstacles.TRASH or spot == obstacles.CRACK or spot == obstacles.BARRIER or spot == obstacles.BIKE or spot == obstacles.WATER: # other obstacles
#add more condition if pinguin and than obs
print('why drop 10? is there obstacle - spot = ', spot, 'lines=', line)
sumTotal -= 10
goodList = [obstacles.PENGUIN, obstacles.CRACK, obstacles.WATER]
for item in goodList:
if item in line :
itemIndex = line.index(item)
if line[itemIndex+1] == obstacles.TRASH or line[itemIndex+1] == obstacles.BARRIER or line[itemIndex+1] == obstacles.BIKE:
sumTotal += 10
print('get up with 10')
return sumTotal

def findTheHighScoreWay(vision, pos):
actionToMove = actions.NONE
scoreLeftLine = 0
scoreFrontLine = 0
scoreRightLine = 0

scoreLeftLine = sumScore([vision[0][0], vision[1][0], vision[2][0], 'left'])
scoreFrontLine = sumScore([vision[0][1], vision[1][1], vision[2][1], 'front'])
scoreRightLine = sumScore([vision[0][2], vision[1][2], vision[2][2], 'right'])
print('left:', vision[0][0], '-', vision[1][0], '-', vision[2][0])
print('front:', vision[0][1], '-', vision[1][1], '-', vision[2][1])
print('right:', vision[0][2], '-', vision[1][2], '-', vision[2][2])

# handle scores when moving between screen sides
print("Right:", scoreRightLine)
print("Left:", scoreLeftLine)
if pos[0] == 2:
scoreRightLine -= 900
print("deducted:",scoreRightLine)
elif pos[0] == 3:
scoreLeftLine -= 900
print("deducted:", scoreLeftLine)


print('score left', scoreLeftLine, ' | score front', scoreFrontLine, ' | score right', scoreRightLine)
print('---------------------------------------------------------------------------------------')

if scoreFrontLine == scoreLeftLine:
if scoreFrontLine == scoreRightLine:
actionToMove = actions.NONE # all are equal - don't turn
else:
if pos[0] < home[0] and vision[0][2] == obstacles.NONE:
actionToMove = actions.RIGHT
if pos[0] > home[0] and vision[0][0] == obstacles.NONE:
actionToMove = actions.LEFT
actionToMove = actions.NONE #all are equal - don't turn
elif scoreLeftLine >= scoreRightLine:
if scoreLeftLine > scoreFrontLine:
actionToMove = actions.LEFT
elif scoreRightLine > scoreFrontLine:
actionToMove = actions.RIGHT
print('action to move', actionToMove)
return actionToMove


6 changes: 4 additions & 2 deletions rose/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Server

game_rate = 1.0
game_duration = 60
game_duration = 0
number_of_cars = 4
is_track_random = True

Expand Down Expand Up @@ -38,7 +38,9 @@
# Score Points

score_move_forward = 10
score_move_backward = -10
score_gas_start = 100
score_move_backward = -5
score_move_backward_obstacle = -5
score_jump = 5
score_brake = 4

Expand Down
9 changes: 8 additions & 1 deletion rose/common/obstacles.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@


def get_random_obstacle():
return random.choice(ALL)
obstacle = ''
num = random.randint(0, 100)
if num < 50:
obstacle = PENGUIN
else:
obstacle = random.choice(ALL)
return obstacle
#return random.choice(ALL)
Binary file modified rose/res/bg/bg_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified rose/res/bg/bg_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified rose/res/bg/bg_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified rose/res/cars/car1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified rose/res/cars/car2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified rose/res/cars/car3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified rose/res/cars/car4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified rose/res/dashboard/dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified rose/res/obstacles/barrier.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified rose/res/obstacles/bike.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified rose/res/obstacles/crack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified rose/res/obstacles/penguin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified rose/res/obstacles/trash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified rose/res/obstacles/water.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 7 additions & 5 deletions rose/server/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,13 @@ def print_stats(self):
def loop(self):
self.track.update()
score.process(self.players, self.track)
if self.timeleft > 0:
self.update_clients()
self.timeleft -= 1
else:
self.stop()
top_scorers = sorted(six.itervalues(self.players), reverse=True)
self.timeleft += 1
for p in top_scorers:
if p.score > 0:
self.update_clients()
else:
self.stop()

def update_clients(self):
msg = message.Message('update', self.state())
Expand Down
2 changes: 1 addition & 1 deletion rose/server/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def reset(self):
self.y = config.matrix_height // 3 * 2 # 1/3 of track
self.action = actions.NONE
self.response_time = 1.0
self.score = 0
self.score = config.score_gas_start

def in_lane(self):
min_x = self.lane * config.cells_per_player
Expand Down
Loading