Tuesday, April 15, 2014

Yum Game ported to BDS C

I've been playing some more with the Briel Altair 8800 running CP/M.

As a larger test of the BDS C compiler I was able to port the "Yum" game that I originally wrote to run on the Briel Apple Replica 1.

Porting it to BDS C was a few hours of work (mostly spent transferring new versions of the code between my Linux desktop and SD card and compiling on the Altair 8800.

The changes required were not too major. I was impressed by the reasonably complete run-time library included with BDS C. In all, the changes I had to make were the following:

  • Includes changed (BDSC C has everything in stdio.h).
  • sizeof does not work for arrays, so used a constant.
  • Arrays cannot be initialized, but can use initptr() function instead.
  • No bool type, so use int.
  • Function declarations have to use old K&R format.
  • Text supports lower case (original Apple 1 version had to be upper case only).
  • Some text lines (like help) made wider due to 80 column screen.
  • Variables cannot be initialized when declared.
  • No strtol() so use atoi().
  • Remove const qualifiers.
  • Clear screen using ANSI escape sequence.

Below is a partial log of a session playing the game against the computer.



#     # #     # #     #
 #   #  #     # ##   ##
  # #   #     # # # # #
   #    #     # #  #  #
   #    #     # #     #
   #    #     # #     #
   #     #####  #     #


Welcome to Yum!
Do you want instructions (y/n) ? y

This is a computer version of the game Yum, similar to games known as Yahtzee,
Yacht and Generala. Each player rolls five dice up to three times and then
applies the dice toward a category to claim points. The game has 12 rounds
during which each player attempts to claim the most points in each category.

The winner is the person scoring the most points at the end of the game.
This version supports up to three players of which any can be human or
computer players.

Categories are as follows:
1'S through 6'S - dice of same type
Low Straight (15) - 1 2 3 4 5
High Straight (20) - 2 3 4 5 6
Low Score - total 21 or more
High Score - total 22 or more
Full House (25) - 3 of a kind and pair
Yum (30) - 5 dice the same
Bonus of 25 points if upper section is 63 or more.

How many human players (0-3)? 1
How many computer players (0-2)? 1
Name of player 1? Jeff
Press to start the game
Wait a few seconds, and type a CR: 

Jeff's turn. Press to roll 
First roll is: 2 2 2 4 5
Enter dice to roll again or D for dice or S for score: 4 5
Second roll is: 2 2 2 2 2
Enter dice to roll again or D for dice or S for score: 

 1  - 1'S
 2  - 2'S
 3  - 3'S
 4  - 4'S
 5  - 5'S
 6  - 6'S
 9  - Low Straight
10  - High Straight
11  - Low Score
12  - High Score
13  - Full House
14  - Yum

Jeff, What category do you want to claim? (1-14)? 14

Altair's turn. Press to roll 
First roll is: 1 1 4 4 5
Altair keeps: 1 1 4 4
Second roll is: 1 1 4 4 5
Altair keeps: 1 1 4 4
Last roll is: 1 1 2 4 4
Altair plays 1'S

Press to continue 

Score after 1 of 12 rounds:

Roll           Jeff    Altair  
1'S                    2       
2'S                            
3'S                            
4'S                            
5'S                            
6'S                            
Sub-total      0       2       
Bonus          0       0       
Low Straight                   
High Straight                  
Low Score                      
High Score                     
Full House                     
Yum            30              
Total          30      2       

Press to continue 

Jeff's turn. Press to roll 
First roll is: 1 2 2 6 6
Enter dice to roll again or D for dice or S for score: 1
Second roll is: 2 2 4 6 6
Enter dice to roll again or D for dice or S for score: 4
Last roll is: 2 2 6 6 6

 1  - 1'S
 2  - 2'S
 3  - 3'S
 4  - 4'S
 5  - 5'S
 6  - 6'S
 9  - Low Straight
10  - High Straight
11  - Low Score
12  - High Score
13  - Full House

Jeff, What category do you want to claim? (1-14)? 13

Altair's turn. Press to roll 
First roll is: 2 4 4 6 6
Altair keeps: 4 4 6 6
Second roll is: 4 4 4 6 6
Altair keeps: 4 4 4 6 6
Altair plays Full House

Press to continue 

Score after 2 of 12 rounds:

Roll           Jeff    Altair  
1'S                    2       
2'S                            
3'S                            
4'S                            
5'S                            
6'S                            
Sub-total      0       2       
Bonus          0       0       
Low Straight                   
High Straight                  
Low Score                      
High Score                     
Full House     25      25      
Yum            30              
Total          55      27      

Press to continue


I put the source code as well as a CP/M binary here on github.  Next, I plan to try porting my text adventure game.

No comments: