Zum Inhalt springen

René’s Avigo Page: The Bridge Display

The Bridge Display

I had some spare hours to write a program that I
wanted to have on the Avigo. It is sort of a bridge trainer, which deals random
hands for you and lets you play the hands. Moreover, it can generate random
hands from sparse descriptions such as AKxxx. The application can be downloaded
from
here.
The
source
is also available.

The display is just big enough for this, as you
can see in the following hardcopy.

Usage

Once you see a hand, you can tap on a card to
start playing. The program will then draw a rectangle frame around the hand,
which is to play next. The winner of each trick will be computed and the
rectangle will go to the winning hand. If the contract is in a suit, you can
tap on the trump rectangle below the hand to change the trump suit before you

start playing.

The menu contains items to undo the last trick,
or to play the complete hand from start. It also lets you generate a new random
hand. Before you start playing, you can also turn the hand clockwise.

A difficult to program feature was generating a
hand from a hand description. To enter a description, tap on the inpout field
below. The normal keyboard will open. You might then edit the hand or enter a
new hand (you can clear the hand description with a menu option). A hand description
contains several lines, each starting with the hand name (N,O,S,W). Capitalization
does not matter. You need not provide all hands. You can enter x for
unimportant small cards. E.g.,

N AKxxx Kxxx QT KQJ
S xxx - xxxxx T9xxx

is a valid hand description. The program will
compute a hand based on the description, when you choose the corresponding menu
entry.

The Source

The program was sort of a quick hack. For an
object oriented programmer the rudimentary C of the Avigo is a pain. My pitty
is with those that program the Avigo in assembler. For this small program
however, productivity is good enough to get results.

I probably met some bugs in the C compiler,
which I overcame by writing very rudimentary C code. E.g. I did not use
multiple assignments with array members. Also I hard a hard time finding the
usual programming trapy with = instead of == etc. Anyway, there was some
strange instability too, which I attribute to the simulator and its inaccurate mouse
display. Finally the program seemed to run fine.

For the novice Avigo programmer, it might be
interesting how I did the card display and the tap recognition. The program
imports five bitmaps (four suit symbols and one for the ten, which is an icon).
While drawing the hand, I initialize four arrays (one for each hand) with
structures, each containing a bounding rectangle for each card and the number
of the card. When the user tabs on the screen, these rectangles are processed
to find the card.

The most critical part was the parser that
generates hands from descriptions. I did it in one single function, which is
really not an elegant way to do it. Now that it works, I don’t want to improve
that design for better readability.

You will notice a lot of global variables. This
is not the way to go in a larger project. To me the program looks like a mess. Also
it is very difficult to keep track of the various states the program is in. For
this project, the simple approach is good enough though.

I also had a strange problem with the text
field. WhenI tried to set a new text, it would only display the first letter. This
I resolved by starting the creating the object with a hand description and
clearing it afterwards.

One more tip! If your simulator hangs (due to an
eternal loop) break it and press CTRL-F2 to reset it. Then you will not get
problems after the next compiler run.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.