AI 2 - Game Playing (Artificial intelligence)

CODE 1

AI - Game PLaying (CODE)

In the last article, i used a linked list to hold the different states instead of an array. since then, ive written a better, more easyer to use list class, and will be using the newer class in this tutorial.

Reasons why we need a linked list, and cannot use an array:

  • Arrays are fixed length, we cannot change there sizes dureing runtime
  • With linked lists, we can remove states we no longer need, (freeing up memory)
  • With linked lists, we can grab more memory as and when we need it
Reasons why im using a coded linked list, and not 1 in an MFC library:
  • Were codeing a console program, lets avoid mfc
  • MFC scares me, i dont like it, and im writing the tutorial
  • Since we can see the source code in this linked list, we know exactly how it works, which i find helps with de-bugging
  • I dont actually know how to use any MFC template linked lists, and again, im the 1 writing the tutorial
The header file with this template linked list in it is contained in the zip (TLList.h), ill not explain the source, as its not part of the AI, but i will give a list of the functions, and what they to :)

  1. CLList<int> IntegerList; declair an object that holds integers
  2. CLList<int> IntegerList(12); declaire a list initiated with 12 integers
  3. CLList<int> IntegerList(12,100); declaire a list initialised with 12 integers, all holding the value 100
  4. GetTotalLinks(); return the number of items in the list
  5. Push(anInteger, Left); add anInteger to either Left or Right side of the list (increacing the sixe of the list)
  6. Push(anInteger, 10); inserts anInteger into place 10 of the list
  7. Pop(Left); Return and remove the item at the left of the list
  8. Pop(10); Return and remove the item at place 10 of the list
  9. Flush(); Empty the list
  10. SetListSize(10); Set the list size to 10, increacing the length if its smaller, and shortening the length if its bigger
  11. SetListSize(10,1); same as above, bute any new list places will be initalised with value 1
  12. IntegerList[n];
NOTE:
  • Position Zero is the same as Position Left
  • Position Right is the same as GetListLen() - 1
  • items added using SetListSize() will be added to the Right
  • itemt removed using SetListSize() will be removed from the right
  • although ive used integer as an example, we will be listing State objects in tic tac toe
  • in this tutorial, we will only be using functions 1,4,5,7 and 12

On the next page we will code the CState class, (where all the interesting stuff happens)

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“It works on my machine.” - Anonymous