NEED HELP FOR PROLOG GAME!!!

109 views
Skip to first unread message

Liew Kin Wai

unread,
Oct 14, 2014, 6:49:13 AM10/14/14
to swi-p...@googlegroups.com
Hi guys, I need some help, I am currently doing a prolog game blackjack, however when the code run in SWI prolog it shows 
ERROR: c:/users/tan may leng/downloads/bj (1).pl:78:35: Syntax error: String too long (see style_check/1)
ERROR: c:/users/tan may leng/downloads/bj (1).pl:80:45: Syntax error: Illegal start of term.
I have no idea what's got wrong with the code, can anyone help me? The rules and commands to play the game are already in the code. can anyone just copy the code, test it and tell me what's wrong with it?

start:-
write('Welcome to Blackjack de Casino!'),nl,
write('Type command. to see available commands'),nl,
write('Type rules. to see Blackjack rules').

command:-
write('Commands                   Functions '),nl,
write('__________________________________________________________________________________________________'),nl,
write('initCard(Bet).             To get the first 2 cards, Bet is the amount to bet'),nl,
write('currentChips.              To display current chips'),nl,
write('restart.                   To restart the game and reset the current chip to initial amount of 100'),nl,
write('halt.                      To quit the game'),nl,nl.

rules:-
write('player will have 100 chips once the game started'),nl,
write('the payrates will be the amount that player placed on their bet'),nl,
write('every game player will take card before dealer'),nl,
write('player can decide to take card or stop'),nl,
write('once player have enough point and decided to stop taking card, dealer will start to take card'),nl,
write('if player points exceed 21, considered lose, dealer will not need to take card for that game'),nl,
write('if player got blackjack, considered win, dealer will not need to take card for that game'),nl,
write('if dealer got blackjack, considered player lose'),nl,
write('dealer will get at least 17 points or else it will not stop taking card'),nl,
write('if dealer points exceed 21, considered lose'),nl,
write('if both player and dealer having points below 21, higher point will be the winner'),nl.
:- style_check(-singleton).
:- dynamic chips/1.

chips(100).

card(J):-J is 10.
card(Q):-Q is 10.
card(K):-K is 10.


currentChips:-chips(X),(X=:=0->nl,write('You have lost all your chips, type restart. to play again'),nl ; write(X)).

restart:-retract(chips(X)),assert(chips(100)) ,write('You have 100 chips now, becareful! gambling is not good').

sum(X,Y,R):- R is X+Y.

playerWin1:- initCard(B), chips(C), N is C+(B*2), retract(chips(C)), assert(chips(N)),
write('Blackjack! You have won '),write(B).

playerLose1:- initCard(B),chips(C), N is C-B, retract(chips(C)),assert(chips(N)),
write('your point overflown, you have lost '),write(B).

playerWin2:- initCard(B), chips(C), N is C+(B*2), retract(chips(C)), assert( chips(N)),
write('you have won '),write(B).

dealerWin1:- initCard(B), chips(C) , N is C-B, retract(chips(C)),assert(chips(N)),
write('dealer got blackjack, you have lost '),write(B).

dealerLose1:- initCard(B), chips(C), N is C+(B*2), retract(chips(C)), assert(chips(N)),
write('dealer's point overflown, you have won '),write(B).

dealerWin2:- initCard(B), chips(C), N is C-B, retract(chips(C)), assert(chips(N)),
write('you have lost '),write(B).

draw:-
write('this round is draw, type init(BetAmout) to play again').

initCard(Bet):-
random_member(Number1,[1,2,3,4,5,6,7,8,9,10,J,Q,K]),
random_member(Number2,[1,2,3,4,5,6,7,8,9,10,J,Q,K]),
write('Your first card is '),write(Number1),nl,
write('Your second card is '),write(Number2),nl,
card(Number1).
card(Number2).
sum(Number1,Number2,Points),
write('Your point is '),write(Points),nl,
(Number1=1,Number2=10 -> playerWin1;
(Number1=1,Number2=J -> playerWin1;
(Number1=1,Number2=Q -> playerWin1;
(Number1=1,Number2=K -> playerWin1;
(Number1=10,Number2=1 -> playerWin1;
(Number1=J,Number2=1 -> playerWin1;
(Number1=Q,Number2=1 -> playerWin1;
(Number1=K,Number2=1 -> playerWin1;continue)))))))).

continue:-
write('do you want to get more card? (y/n)'),nl,
read(Input),
takeCard(Input,Final);
takeCard(Input,Points).

takeCard(y,Z):-
random_member(N,[1,2,3,4,5,6,7,8,9,10,J,Q,K]),
write('you got '),write(N),nl,
sum(N,Z,Final),
write('your point is '),write(Final),
(Final>21->playerLose1;continue).

takeCard(n):-
write('now dealer turns to take card'),nl,
dealerTurns.
takeCard(_):-
write('only y and n are acceptable'),nl.

dealerTurns:-
random_member(DN1,[1,2,3,4,5,6,7,8,9,10,J,Q,K]),
random_member(DN2,[1,2,3,4,5,6,7,8,9,10,J,Q,K]),
card(DN1),
card(DN2),
sum(DN1,DN2,DealerPoints),
(DN1=1,DN2=10 -> dealerWin1;
(DN1=1,DN2=J -> dealerWin1;
(DN1=1,DN2=Q -> dealerWin1;
(DN1=1,DN2=K -> dealerWin1;
(DN1=10,DS2=1 -> dealerWin1;
(DN1=J,DS2=1 -> dealerWin1;
(DN1=Q,DS2=1 -> dealerWin1;
(DN1=K,DS2=1 -> dealerWin1;
(DealerPoints>16 -> dealerStop1;dealerContinue))))))))).

dealerContinue:-
dealerTakeCard(DealerFinal);
dealerTakeCard(DealerPoints).


dealerTakeCard(A):-
random_member(DN,[1,2,3,4,5,6,7,8,9,10,J,Q,K]),sum(DN,A,DealerFinal),
(DealerFinal>21 -> dealerLose1;
(DealerFinal>16 -> dealerStop2;dealerContinue)).

dealerStop1:-
write('dealer now have '),write(DealerPoints),nl,
(Final>DealerPoints -> playerWin2;
(Final<DealPoints -> dealerWin2;
(Final=DealerPoints -> draw))).

dealerStop2:-
write('dealer now have '),write(DealerFinal),nl,
(Final>DealerFinal -> playerWin2;
(Final<DealFinal -> dealerWin2;
(Final=DealerFinal -> draw))).

Boris Vassilev

unread,
Oct 14, 2014, 7:06:58 AM10/14/14
to Liew Kin Wai, swi-p...@googlegroups.com
You have an unescaped apostrophe inside a single-quoted atom somewhere in this rather large listing you've copy-pasted, I'd say. If you use a text editor with source highlighting and line numbers you should be able to spot the error yourself. The editor included in the IDE that comes with SWI-Prolog is quite useful, too.

Another advice is to try and isolate the error in your code so that you can give a minimal example that still has the error that you don't understand.

Cheers,
Boris

Save our in-boxes! http://emailcharter.org

--
You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+...@googlegroups.com.
Visit this group at http://groups.google.com/group/swi-prolog.
For more options, visit https://groups.google.com/d/optout.

Liew Kin Wai

unread,
Oct 14, 2014, 7:16:02 AM10/14/14
to swi-p...@googlegroups.com, kinwa...@hotmail.com


This is the error spotted, but I'm still don't understand how to fix it, can you guide me further?

Sam Neaves

unread,
Oct 14, 2014, 9:28:47 AM10/14/14
to Liew Kin Wai, swi-p...@googlegroups.com
You have periods in the wrong place and you need to be careful where you have phrases like ('dealer's point overflown, you have won ') . 
Reply all
Reply to author
Forward
0 new messages