Authors
Publication
Pub Details
Date
Pages
First, let me introduce myself. I’m 25 years old, live in France (as I’m French) and have had a QL since 1986/87. My main use of the QL is games and game programming, so I’m very glad to have C68. My prefered type of game is one of reflexion and not dexterity (may be because I’m not very quick with my finger. I always loose). Anyway, sometime ago I was able to get back issues of the QLHJ (or QHJ). Reading issue #19 I saw a call for a Pente program. I decided to make one.
Let me first explain the rules of Pente:
On a standard goban (chinese board of 19×19 intersections), each player takes turns placing a stone (like Go stones) of his/her color on the board. The winner is the player who gets five stones in a row, in any of the eight directions, or who has taken 5 pairs of stones from his/her opponent.
Example of winning alignment:
+ + X + + O + + O O O O O X +
+ X + + O + + + + + + + + + +
+ + + O + + X Horizontaly
+ + O + X + +
+ O + + X + + <--- Diagonaly
A pair of stones is taken (captured) when it is inside two opposite stones.
Start Position + + + X O O + +
X's Move + + + X O O X +
End of Move 2 + + + X + + X +
But making a pair this way is does not result in a capture.
Start Position + + + X O + X +
O's Move + + + X O O X +
It’s the capturing move (drop of the X stone) that takes the pair of O’s. The forming of a pair of O’s inside a pair of X’s is allowed and does not result in a capture.
Taking more than one pair with one move (stone) is possible.
X + + X + + +
+ O + O + + + ! is a winning play for each player.
+ + O O + + + X will win by 5 captures.
+ + + ! O O X O will win by alignment.
+ + O O + + +
+ O + O + + +
Additionally, the first move is always on the center of the board (this is a forced move) and the third move (first player’s second move) is always at least three intersections away from the center. The reduces the advantage of the first player.
+ + + + + + + X cannot play it's second move on .
+ . . . . . + O can play it's first move anywhere.
+ . . . . . +
+ . . X . . +
+ . . . . . +
+ . . . . . +
+ + + + + + +
So now you are ready to play Pente.
The big problem when playing is choosing which way you want to win, by alignment or capture. You have to be carefull about what your opponent does, stopping him/her from doing alignment may expose you to capture. This will allow your opponent to try again an alignment, because your blocking stones have been taken, or will make you loose because you lost too many pairs. This game may seem easy, but it can be very difficult and tense.
So now you know the rules. Now about programming the game.
First, I designed the general screen layout. Having a QL, my screen resolution is 512×256, and I wanted to use the entire screen, I base my board size and stone size on this resolution. 256/19 is the limit of the stone size. The stones were created with an Icon Editor ( or Sprite Editor to stick to QL terms) from QTPR. The board will be white with black lines and the stones will be red and green (this is a little like the colors used in the original board version of the game).
I then designed the sprites for the stone and the board. I used a sprite for the board because drawing lines is kind of slow. Board sprites are mainly intersections, except on the border (where there is only three lines connecting), on the corner (where there is only two), and at the GoBan node (the dotted intersections). Board sprites will allow for quick rewrites of the screen when captures take place, since only those intersections affected need to be redrawn instead of the whole board.
The next step was the C programming.
As I have existing game sources, I copy the Main file which contains the window description. This file does not change very much. In main(), I declare the Windows, Status, Loose Items, and so on, with the definition of the acting routines (which may call other bigger functions). I defined the window description, putting in the application window in which the board is drawn and the standard loose item menu (Sleep, Move, Help, Quit (ESC), and Wait). To these loose items I add Computer Play For Me, which has the computer play your next move for you, and How Many Players, which the user uses to select one or two players. I don’t have Computer vs Computer now, but sometime in the future.
What is also standard is the Info Item with the name of the application. I also add other Info Items showing the number of taken pairs by each side and an About selection. I liked the About from QD and FIFI, so I added it in. The Info Item for the Count of pairs taken is just two strings of text that will be redrawn when the count changes.
Now I have a nice looking empty board with mainly all of the Loose Items working. Resize, Move, Quit, Number of Players, Wake are almost always the same, so I just copy them. In fact, as I started with the Windows Demo of C68, I have a module to Pop-up a menu choice either vertically, horizontaly or even in a 2×3 frame with up to six different choices. It allows a standard prompt and the possible choice; i.e, the Quit prompt is “OK to Quit” and the choices are “Yes”, “No”, or “Sleep” with a default of “No.” All is taken care of by the routine, so the caller only needs to see a very sympathetic line of C:
choice = menu_choice_h("Ok to Quit",3,2,"Yes","No","Sleep");
The function returns -1 to choice if the ESC key was pressed, else it returns the C index in the list of choices.
Next I need to write the ‘About’, a new thing for me, which will be a pop-up window with some text. I derived it from the menu_choice() routine, removing all of the paramaters (it’s hard coded) and adding the text and sprite item. I kept the last line as a Loose Menu Item so a mouse user could close the window without having to hit the ESC key (which should be the instinctive way to close this window).
Now I had to put the stones on the board. The first player is Red, so at the start of Pente, the application cursor (in the application window) is the red stone sprite. The hit routine will then get the cursor coordinates, transform them into Board coordinates, and call a specific routine to 1) check for the validity of the move, 2) to see if pairs have been taken, 3) put the stone on the screen, 4) and either make the computer play (if there is only one player, or change the color of the pointer to the green stone sprite.
If the move is not legal (especially for the first and third stones) then a pop-up window is shown, just saying that the move was illegal. ESC or DO in this window will close it. Since you Hit to put your stone, the mouse user will have to change his/her finger to close it. It forces them to read it and to think. This window is made from the menu_choice/About code.
We now have the input/ouput of part of the program. The next step is to provide the brain.
For Pente, I bought the brain from Mr. FrankEinstein, a.k.a. an old french revue “Jeux & Strategie” (Game & Strategy) who once printed a Basic Pente program. I took this program, removed the input/output sections, and concentrated on the internals.
The player side is easy:
- Verify validity of move
- Put the stone
- Check for victory by alignment with the new stone
- If the new stone has captured any pairs, update counters and board, and check for capture victory.
- Swap the player to go
The computer side is not so easy. The program was written to have the computer always play the second player and that is not what I wanted.
For each move the computer looks for any known alignment or partial figures, giving points for each free intersection. The higher the points the better the move. The whole intelligence of the program is the weighting between figures and the intersection with the higher sores in the move played.
To be accurate, there is also and end game behavior. When the computer has already captured 4 pairs, it will give more points to a move that will allow it to take the last pair, hence making a sensitive choice of one move to take the pairs rather than many to win by alignment.
The base of the evaluation is that each time a stone is put on the board the intersections near it gain points.
Once this behavior is translated in C, then comes the hairy things: testing. I did recognize that I had forgotten to add multiple captures.
Once the testing was done, I just had to finish with the details (the Help Loose Item is now easy now that there is a brain). And then you have a wonderful Pente Program.
It only took me two days (Yes!) to write the program, but I had a lot of things already written; menu, skeleton of the program, resize routine, etc. The sprite Editer was a must. I would have wasted a lot of time computing hex numbers to get my sprites. My logo ( a rose ) is a big sprite that came from a previous program, as did the Help and Player sprites used as Loose Items.
It appeared that the most difficult thing was the Hit routine interface, as it evolved with time and the version of C68 (it seems to be stable, but I don’t use it a lot, so I’m less familiar with it than with the Loose Item or even the Menu Item action routines). It’s by smithing that you become a smith.
For once, I have not done a Mode 8 design. Maybe I shall, but the color is just fine for the moment and I don’t think I will double the size of the text items and recreate the sprites in Mode 8, even if this is very simple. Should Masterpice come soon (the new graphics card), I may well use the 512×512 in Mode 8 as well as the 1024×512 in Mode 4.
For those of you that are interested you may get the Pente Executable from me by email (just write to jgrimbert@wtk.suresnes.marben.fr). It’s absolutely free. You may also ask for the sources, but I reserve the right to not give them out. Just send email to the same address.
Please expect a little delay before the answer, as the first request will make me go home, get the files, go back to work, and send them. Also, due to personal/professional travel, requests before 1 December 1995 may be delayed.
Please Note: Tim Swenson has the first public version of the program, but there is an annoying flickering of the counter when the board is redrawn. [ I’m happy just to have a Pente program. I can live with the flicker – ED] Ask me for the lastest version.