PRINT "Read the information inside the program! - type ENTER"
INPUT bananas$
PRINT
REM
REM Who can program the best strategy for a simple game?
REM This is a challenge for YOU!
REM Your strategy can be from 1 to any number of lines of BASIC code.
REM
REM When you have made your strategy you can try it against the other -
REM this program lets the strategies play against each other!
REM The strategi is almost like the doubling in backgammon.
REM Perhaps this will increase the understanding of backgammon...
REM
REM See the comments in the program about the game etc.
REM You will soon identify the built-in strategies and understand how
REM to add your own strategy.
REM You are welcome to copy "jensbest" to your own and improve it.
REM
REM (programming note: perhaps it is better to CALL the strategies....)
REM
REM GROTTAN-BBS could have the best strategy so far in a certain file.
REM When you have made a better strategy, this should be uploaded!
REM
REM Perhaps this kind of competition could be popular in GROTTAN-BBS.
REM
REM Another simple competition could be to find the shortest route
REM to N cities placed at (x1,y1 x2,y2.... xn,yn)
REM
REM Another competition could be to make the best evaluation for chess
REM Who makes a chessprogram (in C) that can let 2 strategies play a
REM long match to determine which is best.
REM If YOU start this project you are welcome to contact me -
REM I have some ideas about it...
REM
REM But first: good luck with this DOUBLING-competiton!
REM
REM greetings
REM Jens Baek Nielsen, Daltoften 15, 8600 Silkeborg, Denmark
REM (Phone 86 81 46 69)
RANDOMIZE (TIMER): REM gets new random numbers for each RUN
CLS
DIM strategy$(100)
strategy$(1) = "jensbest"
strategy$(2) = "jens01"
strategy$(3) = "jens02"
strategy$(4) = "jens03x"
strategy$(5) = "Dummy"
strategy$(6) = "STOP"
x = 1: PRINT "strategies:"
WHILE strategy$(x) <> "STOP"
PRINT x, strategy$(x)
x = x + 1
WEND
INPUT "Strategy for player 1"; play1
INPUT "Strategy for player 2"; play2
DIM matchtot(2): REM the total matches won by the two players
matchtot(1) = 0: matchtot(2) = 0
DIM match(2): REM The situation in the current match for the two players
DIM score(2): REM the score in the current game for the two players
gameto = 30: REM each game goes to 30 points
REM DIM tv123(3)
newmatch: REM **********************************************************
matchto = 5 + 2 * INT(9 * RND)
REM a match goes to 5,7,9,11,13,15,17,19 or 21 points
match(1) = 0: match(2) = 0
newgame: REM **********************************************************
cubeowner = 0: REM noone ownes the cube
score(1) = 0: score(2) = 0: REM each player starts with no points
crawford = 0
cube = 1
meyou = 1 + INT(2 * RND): REM who starts? 1=me, 2=you
newroll: REM **********************************************************
IF crawford = 0 AND cubeowner <> (3 - meyou) AND cube < 64 THEN
REM if no crawford, your opponent does not have the cube, and the
REM cube is not 64, then consider to double
wdouble = 0
GOSUB evt.double
IF wdouble = 1 THEN
REM a doubling was done, will the opponent take or drop?
meyou = (3 - meyou)
GOSUB evt.double
meyou = (3 - meyou)
IF wdouble = 1 THEN
REM it was a TAKE!
cube = cube * 2
cubeowner = (3 - meyou)
ELSE
REM it was a DROP!
GOSUB gameover
IF match(meyou) >= matchto THEN
GOSUB matchover: REM this ought not to happen by a drop!
GOTO newmatch
ELSE
GOTO newgame
END IF
END IF
END IF
END IF
REM the dice is rolled
t = 1 + INT(6 * RND)
REM an odd number is considered negative
IF t = 1 THEN
t = -1
END IF
IF t = 3 THEN
t = -3
END IF
IF t = 5 THEN
t = -5
END IF
score(meyou) = score(meyou) + t: REM the dice is added or subtracted
IF score(meyou) >= gameto THEN
REM the game is simple - the first who reaches 30 point has won the game
REM you cannot improve the game itself -
REM only the doubling strategy!
GOSUB gameover
IF match(meyou) >= matchto THEN
GOSUB matchover
GOTO newmatch
ELSE
GOTO newgame
END IF
END IF
meyou = 3 - meyou: REM now it's the other players turn
GOTO newroll
gameover: REM **********************************************************
me = meyou
opponent = 3 - me
REM the game of backgammon is simulated (also with Crawford!):
REM the game can end in: normal game gammon backgammon
REM 1 point 2 points 3 points
REM occured in 37747 games: 63.43% 33,63% 2.94%
onetwothree = 1
IF score(opponent) < 0 THEN
REM "gammon"
onetwothree = 2
END IF
IF score(opponent) < -30 THEN
REM "backgammon"
onetwothree = 3
END IF
REM tv123(onetwothree) = tv123(onetwothree) + 1
match(me) = match(me) + (cube * onetwothree)
IF match(me) = (matchto - 1) AND match(opponent) < (matchto - 1) THEN
REM the first time a player reaches f.ex. 8 in a match to 9, the crawford
REM rule comes into effect: no doubling is allowed in the following game
crawford = 1
ELSE
crawford = 0
END IF
RETURN
matchover: REM **********************************************************
matchtot(meyou) = matchtot(meyou) + 1
matches = matchtot(1) + matchtot(2)
PRINT
PRINT "Of all the"; matches; " matches "; strategy$(play1); " has won:";
PRINT 100 * matchtot(1) / matches; "%"; " against "; strategy$(play2)
REM x = tv123(1) + tv123(2) + tv123(3)
REM PRINT x, 100 * tv123(1) / x, 100 * tv123(2) / x, 100 * tv123(3) / x
RETURN
evt.double: REM **********************************************************
IF meyou = 1 THEN
player = play1
ELSE
player = play2
END IF
IF player = 1 THEN GOSUB jensbest: RETURN
IF player = 2 THEN GOSUB jens01: RETURN
IF player = 3 THEN GOSUB jens02: RETURN
IF player = 4 THEN GOSUB jens03x: RETURN
IF player = 5 THEN GOSUB dummy: RETURN
RETURN
jensbest: REM **********************************************************
REM jensbest plays like jens02
REM I have not bothered to improve it because of lack of competition -
REM it's here you can do something!
IF wdouble = 1 THEN
RETURN: REM accepts all doubles - stupid; must be improved!
END IF
IF match(3 - meyou) = (matchto - 1) THEN
REM always double if the opponent only needs 1 game to win the match
wdouble = 1
ELSE
IF score(meyou) - score(3 - meyou) > 10 THEN
REM double if I am more than 10 points ahead
REM this should be improved by considering the matchsituation.......
wdouble = 1
END IF
END IF
RETURN
jens01: REM **********************************************************
REM this strategy beats dummy in 52,20% of the matches (500 played)
IF wdouble = 1 THEN
RETURN: REM accepts all doubles
END IF
IF match(3 - meyou) = (matchto - 1) THEN
REM always double if the opponent only needs 1 game to win the match
wdouble = 1
END IF
RETURN
jens02: REM **********************************************************
REM this strategy beats jens01 in 59,44% of the matches (500)
IF wdouble = 1 THEN
RETURN: REM accepts all doubles
END IF
IF match(3 - meyou) = (matchto - 1) THEN
REM always double if the opponent only needs 1 game to win the match
wdouble = 1
ELSE
IF score(meyou) - score(3 - meyou) > 10 THEN
REM double if I am more than 10 points ahead
wdouble = 1
END IF
END IF
RETURN
jens03x: REM **********************************************************
REM this strategy (player 2) beats 61,40% of 500 matches against itself
IF wdouble = 1 THEN
RETURN: REM accepts all doubles
END IF
IF match(3 - meyou) = (matchto - 1) THEN
REM always double if the opponent only needs 1 game to win the match
wdouble = 1
ELSE
IF meyou = 2 THEN
REM with such an IF you can let your strategy play against itself and
REM let one of the players have an improvement (you hope!)
REM jens03x plays like jens01 for player 1
REM jens03x plays like jens02 for player 2
IF score(meyou) - score(3 - meyou) > 10 THEN
REM double if I am more than 10 points ahead
wdouble = 1
END IF
END IF
END IF
RETURN
dummy: REM **********************************************************
REM: stupid: never doubles; accepts all doublings
RETURN