Noughts and Crosses

Last month I read an article about a job interviewer who played TicTacToe with his applicants. It was like an instant shared round of golf, and the interviewer put great store in the correlation of good hires with good players. So in case any DDoE readers might run into that guy, here is TicTacToe (or Noughts and Crosses as it’s known across the pond) in a user form suitable for practice.
 

 
There are several XL versions out there in the wide world of web (though not too many in a user form) and this is just the latest. It’s a refresh of my first XL code that wasn’t a tutorial, written in XLM too many moons ago.

You can set if you go first or second, set if you are X or O, and set if XL plays hard (don’t know if it can be beat), medium (can be beat), or dumb (as in very dumb—makes random legal moves). It’ll keep score. If you play well, you can’t lose. If XL plays well, you can’t win.
 

 
Start refreshes the game, and Reset takes you back to where you can adjust the mode of play. It looks different, but it works fine on a Mac with XL 2011. Its default is the Comic Sans MS font. If you’re playing second, you can control the start square for XL by clicking Start until XL randomly picks the square you want it to use.

The form is available here. After importing, it needs just a one-line macro to run.

Sub TicTacToe()
frmTicTacToe.Show
End Sub

Presumably, that guy giving the interview plays TicTacToe well, so you won’t win. I don’t think you want to lose, either. Or maybe just lose one out of three. I think I read about it on the BBC’s iPad service. If you remember where it was, please comment. And if you beat it with XL playing hard, please say how. Your game is captured in the VBE’s Immediate Window.

Provided as a public service to Dick’s readers. :roll:

…mrt
©¿©¬

14 thoughts on “Noughts and Crosses

  1. when try and import get the following error

    Line 8: Property OleObjectBlob in frmTicTacToe had an invalid file reference.

  2. Jeff –

    Thank you. It’s munged on the server. I’ll replace and advise when it works.

    … mrt

  3. Hi Jeff –

    For reasons I don’t get, I can’t put a form on the server without creating an error in the file. I replaced the link with a spreadsheet containing the form, and it seems to be handled properly. No importing required, and probably a better way to go from the start.

    Please follow the “here” link above. Thank you. Maybe someone can provide insights into the intricacies of forms.

    … mrt

  4. Here’s the explanation for the error discovered by Jeff:

    “When you export a form, there is one .frm file and one .frx file created. Both need to be available and in the same directory (if you open the .frm file in Notepad you will see the OleObjectBlob property refers to the .frx file)”

    I didn’t provide the .frx file from FileGenie. So, either forms go up zipped, or as two downloads, or in a spreadsheet. I think in a spreadsheet seems the best answer.

    Never knew what that .frx file was for ;-)

    … mrt

  5. You Play: First
    You Are: X
    Excel Plays: Hard

    Me: Centre, bottom row
    Excel: Centre, centre row
    Me: Left, top row
    Excel: Right, top row
    Me: Left, bottom row
    Excel: Left, centre row
    Me: Right, bottom row -> WIN!

  6. Hi fanpages –

    Thanks. Nice fork. XL and I went wrong on XL’s second move. It should have been to the opposite corner. With all the reflections and rotations of your position, its a tedious though straight-forward fix.

    XL will play harder soon ;-)

    … mrt

  7. Downloaded this morning.

    Got a win playing the following

    R3C2: X
    R2C2: O
    R2C3: X
    R1C1: O
    R3C3: X
    R1C3: O
    R3C1: X

    Seb

  8. Seb –

    Thank you. XL playing harder once again. New version, same place, same name. Having trouble picking corners. There has to be an intersection routine that looks for where two X strings cross. That’s where X wants to go and O has to get there first. My approach right now is piecemeal. There’s a smarter way. I just have to code it. ;-)

    … mrt

Leave a Reply

Your email address will not be published. Required fields are marked *