Hi, I'm coding a version of the game Othello for my Advanced Higher Computing project (like A level).
I'm having trouble with working out how to get different array elements to interact.
For background purposes, Othello is an 8x8 grid of squares, and there are two sides, black and white. If one side surrounds another side's piece, it flips over and becomes theirs. The player with the most pieces at the end is the winner. I just need to know whether I need to write out 64 different array elements, or if I can make some sort of algorithm? Any help is appreciated.
Othello game - algorithm instead of statements?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 1
- Joined: Wed Oct 31, 2012 10:37 am
Re: Othello game - algorithm instead of statements?
Hi,
Here's some complete yet unreadable C-code for this game. Maybe it is useful, somehow.
Best,
Mark
Here's some complete yet unreadable C-code for this game. Maybe it is useful, somehow.
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- Livecode Opensource Backer
- Posts: 328
- Joined: Mon Dec 05, 2011 5:34 pm
- Contact:
Re: Othello game - algorithm instead of statements?
Hmm, This is highly amusing... I've got an Othello type game in review on the iTunes store as I type this
Look out for 'HexThello' next week 
It's probably easier to have the 64 cell array, because you will find that a sparse array approach tends to the full array towards the end of the game anyway. I tried it with just keeping track of the cells around where the last piece was played and the current 'border' cells, but the amount of code to handle that (and the corresponding errors) was too much. I simply dropped that and had a full array - it takes microseconds to scan the whole board for valid moves and so forth - and can be done in the time between plays with no trouble. It's not as 'clever' but it's very efficient (less variables and handlers required).
The main thing to do with the game is develop the function to handle scanning from a cell in all the 8 directions to see which are viable, then have functions to play a piece (ie do the correct flips), check the board state and know when there is no acceptable place to play.
(Note: recursive scan functions are the easiest here)
After those then the AI player can just use the same functions wrapped in a cpu_player function to decide where to place a piece. For the traditional 8x8 board the weightings of the cells are the fun part to code in
I do remember entering the BASIC code for Othello into an old ZX80 waaay back in 1980 and it had all the features that were required (played an Ok game too!)
Hope that helps a bit,
Dave


It's probably easier to have the 64 cell array, because you will find that a sparse array approach tends to the full array towards the end of the game anyway. I tried it with just keeping track of the cells around where the last piece was played and the current 'border' cells, but the amount of code to handle that (and the corresponding errors) was too much. I simply dropped that and had a full array - it takes microseconds to scan the whole board for valid moves and so forth - and can be done in the time between plays with no trouble. It's not as 'clever' but it's very efficient (less variables and handlers required).
The main thing to do with the game is develop the function to handle scanning from a cell in all the 8 directions to see which are viable, then have functions to play a piece (ie do the correct flips), check the board state and know when there is no acceptable place to play.
(Note: recursive scan functions are the easiest here)
After those then the AI player can just use the same functions wrapped in a cpu_player function to decide where to place a piece. For the traditional 8x8 board the weightings of the cells are the fun part to code in

I do remember entering the BASIC code for Othello into an old ZX80 waaay back in 1980 and it had all the features that were required (played an Ok game too!)
Hope that helps a bit,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.
Visit http://electronic-apps.info for released App information.