Published:2011/8/5 6:59:00 Author:Amy From:SeekIC
By Steve Teal
Apart from playing against another human opponent you can also play against the microprocessor. A handy ’undo’ function is included, which lets you correct any mistakes you made (usually some silly move!).
The game
First we’ll explain the rules, just in case you’re not familiar with them. Four in a row is normally played with two players, who each use different coloured discs. The players take it in turn to drop a disc into any of the columns of a frame. The first one who manages to get four of his discs in a row (horizontally, vertically or diagonally), wins. In this instance the game can also be played against the microcontroller. There are several methods that can be used to implement an automatic opponent. A large number of examples can be found on the Internet. Most of these are based on Alpha-Beta algorithms and there is even one that uses an enormous table to search for the best move. The algorithm in our version isn’t quite an Alpha-Beta one, but it still makes a very capable opponent.
The automatic opponent can be turned on at any time. The micro will then make the next move. The play area is represented by a matrix of 42 bi-colour LEDs.
The players drop a disc down a column using the switches that are underneath each column. When ’four in a row’ are detected the winning line will flash and the game is over. Every move made is also stored, so it is always possible to go back. This even works when a winning line flashes.
The circuit
The game is built round an AT90S2313 microcontroller by Atmel, which runs at 10 MHz. The circuit diagram is shown in Figure 1. As you can see, the LED matrix takes up most of the board. The 12 cathode lines are driven by IC2. This is a HEF4894B, a relatively new addition to the 4000B CMOS family. It is a 12-channel serial to parallel shift register with open drain outputs. This IC was specifically designed as a LED driver and is therefore particularly suitable for our application. With this IC the use of common anode LEDs was the logical choice.
The LEDs are multiplexed. The columns are activated in turn, while the right rows are activated at the same time, malting the required LEDs light up. The LEDs aren’t very bright, but it’s sufficient for indoor use. The current through the LEDs is limited to 20 mA, because the HEF4894B cannot sink more than that. Since they are multiplexed at a ratio of 1:7, the average current is only about 2 to 3 mA. The anodes are driven by IC3, an 8-channel source driver that is connected to port B of the microcontroller.
The software goes through all the columns. Pin PB3 is skipped because this connects to the piezo buzzer. During the scanning of the columns a check takes place to see if a switch is pressed (see the sidebar). This uses a common return signal, which is connected to PDO of the microcontroller. The extra diodes prevent more than one column becoming active when several switches are pressed.
The circuit contains a voltage regulator, so the power source can either be a 9 V battery or mains adapter. The maximum current consumption is about 150 mA, so we would recommend that you use a 300 mA mains adapter.
The idle current of the circuit is 800 μA. This is a bit too much to leave the circuit permanently powered by batteries, so an on/off switch is recommended. The circuit will also work with four AA cells and a diode instead of IC4. The idle current without a voltage regulator is only 1μA and an on/off switch is no longer necessary. This is feasible since the circuit goes into a sleep mode automatically when it hasn’t detected any activity for a certain length of time. The memory contents are saved in this state and it is possible to resume a game again at any time.
Reprinted Url Of This Article: http://www.seekic.com/blog/project_solutions/2011/08/05/Four_in_a_Row__Play_against_each_other_or_against_the_micro_1.html
Print this Page | Comments | Reading(508)
Author:Ecco Reading(30198)
Author:Ecco Reading(3462)
Author:Ecco Reading(3182)
Author:Ecco Reading(3662)
Author:Ecco Reading(5233)
Author:Ecco Reading(3249)
Author:Ecco Reading(3390)
Author:Ecco Reading(3531)
Author:Ecco Reading(3936)
Author:Ecco Reading(3708)
Author:Ecco Reading(3678)
Author:Ecco Reading(3715)
Author:Ecco Reading(6029)
Author:Ecco Reading(3693)
Author:Ecco Reading(4479)