This site requires JavaScript, please enable it in your browser!
Greenfoot back

Report as inappropriate.

mjrb4
mjrb4 presents ...

2008/7/31

Noughts and Crosses Challenge

Presented below is the outline of an unfinished noughts and crosses game. The human plays crosses, and goes first. The computer play's with naughts. However - the computer part isn't written, that's your job! And more than that, the challenge is to code the AI so it can NEVER lose, only win or draw. Anyone up for the challenge? :)

5016 views / 8 in the last 7 days

Tags: game with-source challenge

This scenario is a member of: Challenges


open in greenfoot

There is no HTML 5 translation of this scenario available.
View legacy version (requires Java plugin)

This scenarios uses Java features that are not available for use after conversion to HTML 5. Please try the legacy version, which requires the Java plugin to be installed.

mjrb4mjrb4

2008/7/31

A little more detail... This challenge probably ISN'T the best if you've just started out programming. If you're still getting to grips with the basics, then I'd recommend trying mik's breakout challenge that was posted a few weeks ago, or something similar to that. That said, the challenge here is all about creating and working out the algorithm to create a flawless naughts and crosses player, so you don't have to be a wizard at Java - even if you've come from another programming background and haven't been coding in Java that long, you might still be able to crack this one :) So where do you start? Apart from the obvious (downloading the source) you've got a class (AI) you can modify in any way you like - as long as you don't circumvent the rules and play unfairly! There are also 2 methods in the Grid class that you will need to use - the first one, move, is what you call to place a naught in a square. That's pretty essential to actually do anything! The second, getDescription(), returns a 3x3 array of strings, each representing a different cell and each containing a description of that cell. Apart from that, all the coding is down to you! You've got to first find out a method to win all the time (Google will help you with that - there's plenty of sites out there that explain how) and then you've got to convert that method into a Java algorithm. If a few people take this up, it'd be really interesting to see the differences in how you approached / solved the problem, so feel free to post solutions! Good luck!
mjrb4mjrb4

2008/7/31

Just to make it clear, beacuse I didn't state it above - new classes are perfectly fine :)

Want to leave a comment? You must first log in.

Who likes this?

No votes yet.