Bagh Chal

A 10-line TurboBASIC XL program for the Atari 8-bit computer
Written for 2014 NOMAM programming competition

Bill Kendrick, March 23, 2014

An entry for the NOMAM 2014 10-line TurboBASIC XL game competition.


Objective

Bagh Chal is a strategic, two-player board game that originates in Nepal. One player controls four tigers, the other controls up to twenty goats. Tigers hunt the goats, while goats try to block the tigers' movement.

The game is played on a board consisting of 25 spots, connected by lines; those lines are the direction of valid moves between spots. Tigers capture goats by jumping over them (similar to Checkers). Otherwise, both tigers and goats may only move one space (across one line) at a time.

Player two begins with 20 goats. Until all 20 have been placed, the only move player two may make is to place a goat on an empty spot on the board. After that, player two moves a goat during their turn.


Gameplay

This is a two-player game, controlled by keyboard input. At each prompt, the player is to enter an alphanumeric board location; letter (horizontal) followed by number (vertical), e.g., "A1" for the top left spot, or "C3" for the center spot.


Winning

This implementation of the game does not end. In that respect, it basically acts like a 'smart board and pieces'.

If player 1 is unable to move any of their tigers, the game will get stuck in a loop, waiting for a valid tiger move. In that case, player 2 has won!

If all of the goats have been captured, the game will get stuck in a loop waiting for player 2 to make a valid goat move. In that case, player 1 has won!

Note: Some people who play this game stop after 5 (rather than all 20) goats have been captured.


Development

I have wanted to make a Bagh Chal game (specifically, a web-based one for my Bill's Games website) since I first saw a board and pieces at local Tibetan gift shop, back in the 1990s.

To make this game, I simply reminded myself how the game works (thanks, Wikipedia), and tried an online version, and read another page's description of the game.

I decided to use the state of the screen (by using LOCATE) and simple rules on what directions moves can be, depending on what spot the piece is in, and after modularizing some things, was able to cram it into 10 lines.

This was the first game I developed for the NOMAM 2014 contest using my Linux laptop, rather working directly on my Atari 1200XL. I used some tools I put together to convert plain ASCII into a working TurboBASIC XL program, running under an emulator: linux2tbasicxl.

Fun fact: I had never actually played Bagh Chal until I tried an online version today!


Line-by-line Breakdown of the Source Code

Setup

10 GRAPHICS 2:DIM B$(45):B$="t- - - -t!\!/!\!/! - - - - !/!\!/!\!012321230":? #6;" A B C D E":FOR I=37 TO 45:N=(VAL(B$(I,I))*9)+1 20 IF I MOD 2=1:? #6;CHR$((I-37)/2+177);:ELSE :? #6;" ";:ENDIF :? #6;B$(N,N+8):NEXT I:G=20:DIM I$(2):Q=1000

Main loop

Tiger's turn

100 REPEAT :? K;" T from":GOSUB Q:UNTIL C=116:X1=X:Y1=Y:REPEAT :? "T to":GOSUB Q:DX=ABS(X1-X):DY=ABS(Y1-Y) 105 OK=(C=32 AND (DX=DY OR X1=X OR Y1=Y) AND DX<3 AND DY<3 AND (((X1+Y1) MOD 2)=0 OR X1=X OR Y1=Y)) 110 IF DX=2 OR DY=2:GX=(X1+SGN(X-X1))*2+1:GY=(Y1+SGN(Y-Y1))*2+1:LOCATE GX,GY,C1:IF C1<>231:OK=0:ENDIF :ENDIF :UNTIL OK 120 C=116:GOSUB 2000:IF G>0:REPEAT :? G;" G at":GOSUB Q:UNTIL C=32:POSITION X*2+1,Y*2+1:? #6;"g":G=G-1:ELSE

Goat's turn

140 REPEAT :? "G from":GOSUB Q:UNTIL C=231:X1=X:Y1=Y:REPEAT :? "G to":GOSUB Q:DX=ABS(X1-X):DY=ABS(Y1-Y) 150 OK=(C=32 AND DX<2 AND DY<2 AND (((X1+Y1) MOD 2)=0 OR X1=X OR Y1=Y)):UNTIL OK:C=231:C1=0:GOSUB 2000:ENDIF :GOTO 100

Subroutines

Input

1000 TRAP Q:REPEAT :INPUT I$:X=ASC(I$(1,1))-65:Y=ASC(I$(2,2))-49:UNTIL X>=0 AND X<6 AND Y>=0 AND Y<6:LOCATE X*2+1,Y*2+1,C:TRAP 32768:RETURN

Draw the move

2000 POSITION X1*2+1,Y1*2+1:? #6;" ":POSITION X*2+1,Y*2+1:? #6;CHR$(C):IF C1=231:POSITION GX,GY:? #6;" ":K=K+1:ENDIF :RETURN

Download


Bill Kendrick, 2014, nbs@sonic.net, New Breed Software
Other games I wrote for NOMAM 2014