Skip to content

Commit

Permalink
Update: prediction fixes and making sure soccer ball doesn't spawn in…
Browse files Browse the repository at this point in the history
… the goal
  • Loading branch information
patham9 committed Jan 20, 2024
1 parent b7762c4 commit 8901aaf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions nace.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ def NACE_Predict(Time, FocusSet, oldworld, action, rules, customGoal = None):
scores, highscore, rule = positionscores[(y,x)]
#for rule in rules:
if _RuleApplicable(scores, highscore, highesthighscore, rule):
if highscore == 1.0:
newworld[VALUES] = rule[1][3]
if highscore < 1.0 and rule[1][3][0] > 0:
continue #only use a rule that predicts score increase when certain!
newworld[VALUES] = rule[1][3]
newworld[BOARD][y][x] = rule[1][2]
used_rules_sumscore += scores.get(rule, 0.0)
used_rules_amount += 1
Expand Down Expand Up @@ -359,7 +360,7 @@ def _MatchHypotheses(FocusSet, oldworld, action, rules):
if CONTINUE:
continue
scores[rule] /= (len(precondition)-2)
if scores[rule] > 0.0 and scores[rule] > highscore or (scores[rule] == highscore and highscorerule is not None and len(rule[0]) > len(highscorerule[0])):
if scores[rule] > 0.0 and (scores[rule] > highscore or (scores[rule] == highscore and highscorerule is not None and len(rule[0]) > len(highscorerule[0]))):
highscore = scores.get(rule, 0.0)
highscorerule = rule
positionscores[(y,x)] = (scores, highscore, highscorerule)
Expand Down
4 changes: 3 additions & 1 deletion world.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ def World_Move(loc, world, action):
world[VALUES] = tuple([world[VALUES][0] + 1] + list(world[VALUES][1:])) #the first value +1 and the rest stays
while True:
xr, yr = (random.randint(0, width-1), random.randint(0, height-1))
if oldworld[BOARD][yr][xr] == FREE and xr > 1 and yr > 1 and xr < width-2 and yr < height-2:
if oldworld[BOARD][yr][xr] == FREE and xr > 1 and yr > 1 and xr < width-2 and yr < height-2 and \
oldworld[BOARD][yr+1][xr] == FREE and oldworld[BOARD][yr-1][xr] == FREE and \
oldworld[BOARD][yr][xr+1] == FREE and oldworld[BOARD][yr][xr-1] == FREE:
world[BOARD][yr][xr] = SBALL
break
#CUP
Expand Down

0 comments on commit 8901aaf

Please sign in to comment.