Prolog "Syntax Error: Operator Expected" Error -
i editing following game , have 2 errors left; both @ bolded , italicized "!." (in forum listed *'s). doesn't happen in other times used , have searched other answers, deleted spaces, etc. , can't seem find answer. please let me know if have advice! :)
the first error after section titled "gate" , after section titled "key"
/* little adventure game. there 3 entities: you, treasure, , ogre. there 6 places: valley, path, cliff, fork, maze, , mountaintop. goal treasure without being killed first. */ /* first, text descriptions of places in game. */ description(valley, 'you in pleasant valley, trail ahead.'). description(path, 'you on path, ravines on both sides.'). description(cliff, 'you teetering on edge of cliff.'). description(fork, 'you @ fork in path.'). description(maze(_), 'you in maze of twisty trails, alike.'). description(mountaintop, 'you on mountaintop.'). description(gate, 'you @ gate.'). description(teleport, 'you teleport gate.'). description(key, 'you stuble on rock , under it.'). description(didntdropkey, 'dont forget drop .....'). /* report prints description of current location. */ report :- at(you,x), description(x,y), write(y), nl. assert(at(you,cliff)). report. retract(at(you,cliff)). assert(at(you,valley)). report. /* these connect predicates establish map. meaning of connect(x,dir,y) if @ x , move in direction dir, y. recognized directions forward, right, , left. */ connect(valley,forward,path). connect(path,right,cliff). connect(path,left,cliff). connect(path,forward,fork). connect(fork,left,maze(0)). connect(fork,right,gate). connect(gate,right,mountaintop). connect(gate,left,didntdropkey). connect(gate,forward,didntdropkey). connect(maze(0),left,maze(1)). connect(maze(0),right,maze(3)). connect(maze(1),left,maze(0)). connect(maze(1),right,maze(2)). connect(key,left,teleport). connect(key,right,maze(0)). connect(maze(3),left,maze(0)). connect(maze(3),right,maze(3)). /* move(dir) moves in direction dir, prints description of new location. */ move(dir) :- at(you,loc), connect(loc,dir,next), retract(at(you,loc)), assert(at(you,next)), report, !. /* if argument not legal direction, print error message , don't move. */ move(_) :- write('that not legal move.\n'), report. /* shorthand moves. */ forward :- move(forward). left :- move(left). right :- move(right). /* if , ogre @ same place, kills you. */ ogre :- at(ogre,loc), at(you,loc), write('an ogre sucks brain out through\n'), write('your eye sockets, , die.\n'), retract(at(you,loc)), assert(at(you,done)), !. /* if , ogre not in same place, nothing happens. */ ogre. /* if , treasure @ same place, win. */ key :- at(you,key), write('you have found key'), retract(at(you,maze(2)), assert(at(you,key)), ***!.*** key. /* print out you're @ key need add key used later. */ /* teleport function action taken if key , turn right teleport gate*/ teleport :- at(you,teleport), write('you teleported gate'), retract(at(teleport)), assert(at(you,gate)), !. teleport. didntdropkey :- at(you,didntdropkey), write('you didnt drop key , stuck lightning.\n'), retract(at(you,dintdropkey)), assert(at(you,done)), !. didntdropkey. treasure :- at(treasure,loc), at(you,loc), write('there treasure here.\n'), write('congratulations, win!\n'), retract(at(you,loc)), assert(at(you,done)), !. /* if , treasure not in same place, nothing happens. */ treasure. /* if @ cliff, fall off , die. */ gate :- at(you,gate), write('you use key found earlier open gate.\n'), move(at(you, mountaintop), move(at(you, treasure), ***!.*** gate. cliff :- at(you,cliff), write('you fall off , die.\n'), retract(at(you,cliff)), assert(at(you,done)), !. /* if not @ cliff nothing happens. */ cliff. /* main loop. stop if player won or lost. */ main :- at(you,done), write('thanks playing.\n'), !. /* main loop. not done, move user , make it. run our special behaviors. repeat. */ main :- write('\nnext move -- '), read(move), call(move), ogre, treasure, gate, cliff, main. /* starting point game. assert initial conditions, print initial report, start main loop. */ go :- retractall(at(_,_)), % clean previous runs assert(at(you,valley)), assert(at(ogre,maze(3))), assert(at(treasure,mountaintop)), write('this adventure game. \n'), write('legal moves left, right, or forward.\n'), write('end each move period.\n\n'), report, main.
retract(at(you,maze(2)), ^ move(at(you, mountaintop), ^ move(at(you, treasure), ^
you're missing closing paren in these places. makes prolog think these clauses don't end @ cut.
Comments
Post a Comment