Jump to content
IGNORED

Updated OXO game ... Reworked 'AI' and scoring system ....


TEXAS_JOE

Recommended Posts

  • 9 years later...

Great presentation, but the AI is missing a very basic requirement, which is blocking an imminent 3-in-a-row win by the human player.

A simple way to mitigate that is to:

  • Represent a player cell as 1, a computer cell as 10, and 0 for an empty cell in a 9 cell single-dimension array (1..9).
  • Have a set of DATA statements with each row containing the cells in the array representing the columns, rows and diagonals as array indices such as below. The order of the cells does not matter.
    • DATA 1,2,3 ! First row

      DATA 4,5,6 ! Second row 

      etc...

  • Read the DATA sequentially in sets of 3 and check the contents of the indexed array cells, adding them up. For example, if the first row contains 1,0,1, then the total for that row will be 2. If it contains 10,1,0 then it will be 11.

  • Any result of 2 indicates an imminent win by the player and thus the cell in that group that has a 0 in it needs to be claimed by the computer immediately in order to block the win.

This should solve that problem :)
 

 

 

  • Like 1
Link to comment
Share on other sites

2 hours ago, Vorticon said:

the AI is missing a very basic requirement, which is blocking an imminent 3-in-a-row win by the human player.

Hi vorticon

I programmed it deliberately to randomly fail.  First off it was blocking every single move the player made and never strayed, and this in the end made for a very frustrating experience as every game ended with no winner.  So I decided it should not be quite as perfect.  There is code in there that detects if the player has two of his markers in a row vertically, horizontally, and diagonally, and it can place it's own marker in the way, but this does not happen all the time.  It can even win games against the player.  I'll note down your code though so that should I redo it another time I will implement that, it looks more compact than the code I used.  ;)

Link to comment
Share on other sites

vivitur = passive voice of vivere, 3rd person singular ("it is lived", in the sense of "you live")

ingenio = ablative case of ingenium ("by the genius", "by the talent")

cætera = alternative form of cetera ("the others", cf. "et cetera")

mortis = genitive singular ("of the death")

erunt = future tense of esse ("will be")

 

I'd translate it as "you live by your genius, everything else will die".

 

In German you could do an almost verbatim translation as "Es wird durch den Geist gelebt; alles andere ist des Todes."

  • Like 2
Link to comment
Share on other sites

Germanic languages lost the synthetic passive voice long ago; that is, we have to construct the passive voice (English "be done", German "getan werden/sein"). German could profit from its inflections more than English (four cases), but as in most other related languages, articles are required, and this is where Latin wins. Essentially, Latin has a very low redundancy, while English and German and most other modern languages show a higher degree.

 

Redundancy in natural languages is not a bad thing. It makes our languages better understandable, with a lower chance of misunderstanding.

 

If you have a look at more distant language families, it is still surprising how many similarities there are in the Indo-European family.

 

Edit: This was my 5k post, but it was not computer-related. I should have checked before. ?

 

Edited by mizapf
  • Like 3
Link to comment
Share on other sites

12 hours ago, Retrospect said:

Hi vorticon

I programmed it deliberately to randomly fail.  First off it was blocking every single move the player made and never strayed, and this in the end made for a very frustrating experience as every game ended with no winner.  So I decided it should not be quite as perfect.  There is code in there that detects if the player has two of his markers in a row vertically, horizontally, and diagonally, and it can place it's own marker in the way, but this does not happen all the time.  It can even win games against the player.  I'll note down your code though so that should I redo it another time I will implement that, it looks more compact than the code I used.  ;)

Got it :)

  • Like 1
Link to comment
Share on other sites

TIC-E,TIC-F,TIC-G <EA5 (someone be kind and build me a cart image! :) )
TIC-X < XBasic 

This is my latest and probably final version.  The AI is much more cunning.  It first looks to see if it can win, then if that's not possible it looks at your markers to try to block you, otherwise it will build up a line of it's own markers.  

 

The game now has a much more "TI Feel" to it.  It's graphics are similar to the MB Connect-4.  There's a little tune in the title screen, it plays until you press a key.  

  • Like 5
Link to comment
Share on other sites

Looks great and plays well. 

Here's a challenge: let the computer play itself by randomly picking cells for each side and check for a win or loss with each move. It will know nothing about strategy. Each game will be stored play by play in a State array of 9 elements with each element representing the entire state of the board for each turn. If a win or loss occurs, the State array will be stored in either a Win or Lose parent array where each element is a State array of a complete game. No need to store games that result in a draw, which should reduce the size of the arrays considerably.

After several thousand iterations, the computer should be able to play a perfect game and the way it will do it is as follows:

  • If the computer goes first, then it should randomly pick a game from the Win array. 
  • If the computer goes second and for every subsequent computer play, it will check its current position against the Win array for the current turn number:
    • For each element in the Win array, look up the board position for the current turn and keep repeating until a match is found in which case the computer will play the move recorded in the next turn. 
    • If no Win array match is found, then the process will be repeated for the Lose array. If a match is found for the current turn, then the cell recorded for the next turn will be marked as excluded in a temporary Exclude array and the computer will keep checking the Lose array in the same manner. Once that process is complete, the computer will randomly pick a cell to play which will not be in the Exclude list.
  • Check for a winning game after each turn, and if none is found after the last cell is played then the game is a draw. The computer cannot lose a game in this process.

This is probably what Joshua in War Games did ?

  • Like 3
Link to comment
Share on other sites

I like your idea Vorticon, unfortunately such a thing is beyond my level of coding or comprehension :)

If anyone wants to try this , I can provide the XB256 source code for them to have a go at.

 

TIC TAC TOE REVISION 2a.txt

 

Note: It really didn't HAVE to be in XB256, it's just, that's my go-to coding language I automatically program in that.

Edited by Retrospect
  • Like 4
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...