Published:2011/8/8 1:19:00 Author:Amy From:SeekIC
By Steve Teal
Software
The software for the microcontroller is written in assembler and developed using AVR Studio from Atmel. This is freely available from the manufacturer’s website. Apart from the source code (found in the file ’inaline.asm’), you will also need an include file (2313def.inc), which is included as standard with AVR Studio.
Unfortunately, there is not enough room here to explain the workings of the software in detail, but we can give an overview of the more important routines. There is also a further explanation of the search algorithm in the sidebar.
Apart from running the usual initialization routines and setting up the timer, the processor also checks at switch-on if a game was still in progress. This is easily done by inspecting the value of the variable NEXT_MOVE. The value here holds the number of moves made, starting at zero. Therefore any value other than zero means that a game is still in progress.
The program checks continuously how many times the timer, which was set up at the start, has overflowed. Every time a switch is pressed the counter will be reset. This is how the program determines if it is time to turn itself off automatically.
Before the device is turned off, the processor first checks if a winning line is flashing. If that is the case, the board is cleared using the moving diagonal line of LEDs and the game is reset. The timer then has to run its course again before finally turning off.
Once the microcontroller is in its sleep mode there is not much that can wake it up again. It so happens that all internal clocks have been stopped. But just before the sleep mode is started, external interrupt 0 is activated. Shift key SI can then be used to start the associated interrupt routine. The most important task of this routine is of course to clear the bit for sleep mode in the control register of the microcontroller.
Strength of play
We’ve compared our program to several others on the Internet and of course to some human players as well. In general we found that our device plays quite well, especially when you compare the processor speed to that of a typical PC platform! And finally we would like to draw your attention to the website of Keith Pomakis. www.pomaki5.com/-pomakis/ c4. Although there are numerous other sites about games such as four in a row and artificial intelligence, this site is one of the few which has a great example of a true Alpha-Beta game called ’connect 4’. Furthermore, the fully documented source code is freely available.
Reprinted Url Of This Article: http://www.seekic.com/blog/project_solutions/2011/08/08/Four_in_a_Row__Play_against_each_other_or_against_the_micro_4.html
Print this Page | Comments | Reading(305)
Author:Ecco Reading(30181)
Author:Ecco Reading(3461)
Author:Ecco Reading(3181)
Author:Ecco Reading(3661)
Author:Ecco Reading(5231)
Author:Ecco Reading(3248)
Author:Ecco Reading(3390)
Author:Ecco Reading(3530)
Author:Ecco Reading(3935)
Author:Ecco Reading(3707)
Author:Ecco Reading(3677)
Author:Ecco Reading(3714)
Author:Ecco Reading(6028)
Author:Ecco Reading(3692)
Author:Ecco Reading(4478)