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
- 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
CLList<int> IntegerList;
declair an object that holds integersCLList<int> IntegerList(12);
declaire a list initiated with 12 integersCLList<int> IntegerList(12,100);
declaire a list initialised with 12 integers, all holding the value 100GetTotalLinks();
return the number of items in the listPush(anInteger, Left);
add anInteger to either Left or Right side of the list (increacing the sixe of the list)Push(anInteger, 10);
inserts anInteger into place 10 of the listPop(Left);
Return and remove the item at the left of the listPop(10);
Return and remove the item at place 10 of the listFlush();
Empty the listSetListSize(10);
Set the list size to 10, increacing the length if its smaller, and shortening the length if its biggerSetListSize(10,1);
same as above, bute any new list places will be initalised with value 1IntegerList[n];
- 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)
Comments