Update by BlueChip

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3901 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Daniel Stenberg 2003-07-29 06:55:29 +00:00
parent 8266df0a03
commit c5a26b0eb7
2 changed files with 202 additions and 245 deletions

View file

@ -1,183 +1,47 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2003 Blue Chip
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
/*
Designed, Written, AI Bots, the lot ...BlueChip =8ªD#
Thanks espcially to
Hardeep, DevZer0, LinusN
DevZer0, LinusN, Zagor
for their help with understanding Rockbox & the SDK
Please note that the code formatting is not that which was
produced originally, but has been updated by whoever
ported it to the plugin system.
I am sure it was done with good reason, so I have not
redone it!
*/
#include "plugin.h"
/*
* Version Date Who Comment
* -------- -------- ---- ------------------------------------------------
* 1.3 20030729 BC Fixed display bug introduced by port to plugin
* Updated documentation
* 1.2 2003 Ported to new plugin system
* 1.1 20030625 BC Flash board when invalid move to used aquare
* Fixed "pause computer" for real harware!
* Added USB_CONNECTED support
* Ensure correct fonts on the way in and out
* 1.0 20030622 BC Release
*
*
* Todo:
* # More AI :)
* # Reintroduce suspend feature under plugin system
*/
#ifdef HAVE_LCD_BITMAP
/* the following #define had to be taken from Button.c
'cos it is not defined in the header!! */
/* how long until repeat kicks in */
#define REPEAT_START 6
/* player types */
#define HUMAN false
#define AIBOT true
/* for domove() */
#define CHECK false
#define MAKE true
/* screen coords - top left x&y */
/* game over */
#define go_tlx 71
#define go_tly 17
/* WiNS */
#define win_tlx 63
#define win_tly 1
/* DRaW */
#define draw_tlx 59
#define draw_tly 1
/* scores */
#define sc_tlx 65
#define sc_tly 39
/* logo */
#define logo_tlx 65
#define logo_tly 2
/* board sqaures -
* there are a number of routines that expect these values asis
* do not try to play with these, you will likely kill the program
*/
#define PLAYERX 0
#define PLAYERO 1
#define POSS 2
#define CHOICE 3
#define EMPTY 4
#define BORDER 5
/* Who gets first turn */
#define FIRST PLAYERX
#define DF_PLX HUMAN
#define DF_AIX NONE
#define DF_PLO AIBOT
#define DF_AIO WEAK
/* Oponent skill level / help level
* -------- ---------------------------------------------------
* NONE no ai / no help
* WEAK random valid move / show all possible
* AVERAGE most pieces (random) / all + most pieces
* SMART most pieces (weighted/random) / all + weighted
* EXPERT
* GURU
*/
#define NONE 0
#define WEAK 1
#define AVERAGE 2
#define SMART 3
#define EXPERT 4
#define GURU 5
#define BEST 3 /* the best ai alogrithm currently available */
/* these are for code clarity, do not change them! */
#define LEFT 0x08
#define RIGHT 0x04
#define UP 0x02
#define DOWN 0x01
/* This represents the maximum number of possible moves
* I have no idea what the real maximum is, buts tests
* suggest about 10
*/
#define MAXPOSS 20
struct move
{
int x;
int y;
int taken;
int rank;
bool player;
};
/*===================================================================
* Procedure prototypes
*==================================================================*/
static void changeplayer(bool pl);
static int othstrlen(char* s);
static void othprint(unsigned char x, unsigned char y, char ch, bool upd);
static void othprints(unsigned char x, unsigned char y, char* s, bool upd);
static void initscreen(void);
static void show_board(void);
static void flashboard(void);
static void show_grid(void);
static void show_score(bool turn);
static void show_players(void);
static void show_f3(bool playing);
static void hilite(struct move* move, bool on);
static void show_endgame(unsigned char scx, unsigned char sco);
static void initboard(void);
static int getmove(struct move* move, struct move* plist,
unsigned char* pcnt, bool turn);
static int checkmove(unsigned char x, unsigned char y, bool pl,
unsigned char dir, bool type);
static void domove(struct move* move, bool type);
static bool calcposs(struct move* plist, unsigned char* pcnt, bool turn);
static int getplist(struct move* plist, unsigned char pl);
static unsigned char reduceplist(struct move* plist, unsigned char pcnt,
unsigned char ai_help);
static void smartranking(struct move* plist, unsigned char pcnt);
static int plist_bytaken(const void* m1, const void* m2);
static int plist_byrank(const void* m1, const void* m2);
static void clearposs(void);
/*===================================================================
* *static* local global variables
*==================================================================*/
/* Plugin header */
#include "plugin.h"
static struct plugin_api* rb;
/* score */
static struct
{
int x;
int o;
} score;
/* 8x8 with borders */
static unsigned char board[10][10];
/* player=HUMAN|AIBOT */
static bool player[2] = {DF_PLX, DF_PLO};
/* AI = WEAK|AVERAGE|SMART|EXPERT|GURU
Help=NONE|WEAK|AVERAGE|SMART|EXPERT|GURU */
static unsigned char ai_help[2] = {DF_AIX, DF_AIO};
/* is a game under way */
static bool playing = false;
/* who's turn is it? */
static bool turn = FIRST;
/***************************************************************************/
/***************************************************************************/
/* OTHFONT.H */
/***************************************************************************/
/***************************************************************************/
/* Don't reorder this array - you have been warned! */
enum othfontc {
@ -443,6 +307,13 @@ static unsigned char othfont[of_eos][6] = {
};
/***************************************************************************/
/***************************************************************************/
/* OTHLOGO.H */
/***************************************************************************/
/***************************************************************************/
/*
######### # # ### ## ## ###
@ -575,12 +446,135 @@ static void showlogo(int x, int y, bool on)
}
/***************************************************************************/
/***************************************************************************/
/* OTHELO.H */
/***************************************************************************/
/***************************************************************************/
/* the following #define had to be taken from Button.c
'cos it is not defined in the header!! */
/* how long until repeat kicks in */
#define REPEAT_START 6
/* player types */
#define HUMAN false
#define AIBOT true
/* for domove() */
#define CHECK false
#define MAKE true
/* screen coords - top left x&y */
/* game over */
#define go_tlx 71
#define go_tly 17
/* WiNS */
#define win_tlx 63
#define win_tly 1
/* DRaW */
#define draw_tlx 59
#define draw_tly 1
/* scores */
#define sc_tlx 65
#define sc_tly 39
/* logo */
#define logo_tlx 65
#define logo_tly 2
/* board sqaures -
* there are a number of routines that expect these values asis
* do not try to play with these, you will likely kill the program
*/
#define PLAYERX 0
#define PLAYERO 1
#define POSS 2
#define CHOICE 3
#define EMPTY 4
#define BORDER 5
/* Who gets first turn */
#define FIRST PLAYERX
#define DF_PLX HUMAN
#define DF_AIX NONE
#define DF_PLO AIBOT
#define DF_AIO WEAK
/* Oponent skill level / help level
* -------- ---------------------------------------------------
* NONE no ai / no help
* WEAK random valid move / show all possible
* AVERAGE most pieces (random) / all + most pieces
* SMART most pieces (weighted/random) / all + weighted
* EXPERT
* GURU
*/
#define NONE 0
#define WEAK 1
#define AVERAGE 2
#define SMART 3
#define EXPERT 4
#define GURU 5
#define BEST 3 /* the best ai alogrithm currently available */
/* these are for code clarity, do not change them! */
#define LEFT 0x08
#define RIGHT 0x04
#define UP 0x02
#define DOWN 0x01
/* This represents the maximum number of possible moves
* I have no idea what the real maximum is, buts tests
* suggest about 10
*/
#define MAXPOSS 20
struct move
{
int x;
int y;
int taken;
int rank;
bool player;
};
/*===================================================================
* local global variables
* THIS IS THE DATA THAT NEEDS TO BE SAVED TO ALLOW THE GAME
* TO CONTINUE ...THE CONTINUE FEATURE DOES NOT WORK UNDER THE
* NEW PLUGIN SYSTEM!
*==================================================================*/
/* score */
static struct
{
int x;
int o;
} score;
/* 8x8 with borders */
static unsigned char board[10][10];
/* player=HUMAN|AIBOT */
static bool player[2] = {DF_PLX, DF_PLO};
/* AI = WEAK|AVERAGE|SMART|EXPERT|GURU
Help=NONE|WEAK|AVERAGE|SMART|EXPERT|GURU */
static unsigned char ai_help[2] = {DF_AIX, DF_AIO};
/* is a game under way */
static bool playing = false;
/* who's turn is it? */
static bool turn = FIRST;
/********************************************************************
* strlen ofr use with othello print system
********************************************************************/
static int othstrlen(char* s)
{
int i;
for(i=0; s[i]!=of_eos; i++);
@ -730,10 +724,14 @@ static void show_players(void)
if (player[PLAYERX]==AIBOT)
scs[2] = of_c;
else
scs[2] = of_h;
scs[4] = ai_help[PLAYERX] +of_0;
if (player[PLAYERO]==AIBOT)
scs[8] = of_c;
else
scs[8] = of_h;
scs[10] = ai_help[PLAYERO] +of_0;
othprints( 2,58, &scs[0], true);
@ -1151,11 +1149,11 @@ static unsigned char reduceplist(struct move* plist, unsigned char pcnt, unsigne
/* ------------------------------------------------- */
case GURU:
break;
/* ------------------------------------------------- */
/* ------------------------------------------------- */
case EXPERT:
break;
/* ------------------------------------------------- */
/* this player will favour certain known moves */
/* ------------------------------------------------- */
/* this player will favour certain known moves */
case SMART:
if (pcnt>1)
{
@ -1167,8 +1165,8 @@ static unsigned char reduceplist(struct move* plist, unsigned char pcnt, unsigne
pcnt = i;
}
/* FALL THROUGH */
/* ------------------------------------------------- */
/* reduce possibilites to "most pieces taken" */
/* ------------------------------------------------- */
/* reduce possibilites to "most pieces taken" */
case AVERAGE:
if (pcnt>1)
{
@ -1179,7 +1177,7 @@ static unsigned char reduceplist(struct move* plist, unsigned char pcnt, unsigne
pcnt = i;
}
break;
/* ------------------------------------------------- */
/* ------------------------------------------------- */
default:
// you should never get here!
break;
@ -1353,7 +1351,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
TEST_PLUGIN_API(api);
(void)parameter;
rb = api;
quit = false;
do /* while !quit */

View file

@ -1,26 +1,19 @@
Introduction to Othelo
======================
Othelo is based on a popular board game. This is by no means the first
computer port of this game - the most famous port I can name was "Reversi".
Othelo is based on a popular board game. This is by no means the first computer port of this game - the most famous port I can name was "Reversi".
The objective is to 'capture' more squares of the board than your opponent.
Each turn you claim a single, previously unclaimed, square of the board. But
EVERY move MUST result in the taking of at least one of your opponents
squares.
Each turn you claim a single, previously unclaimed, square of the board. But EVERY move MUST result in the taking of at least one of your opponents squares.
An opponents square may be captured by placing your pieces either side of it.
Either vertically, horizontally or diagonally.
An opponents square is captured by placing your pieces either side of it. Either vertically, horizontally or diagonally.
The rules are mind-numbingly simple ...but, like Chess, the strategy for
regular success is far from obvious.
The rules are mind-numbingly simple ...but, like Chess, the strategy for regular success is far from obvious.
Further guidance on playing can be found at:
http://home.nc.rr.com/othello/strategy/midgame/
...although I would like to add that all of the AI Bots (Computer opponents)
(currently three thereof) were written by yours truly without reference to
these type of guides.
...although I would like to add that all of the AI Bots (Computer opponents) (currently three thereof) were written by yours truly without reference to these type of guides :-)
Controls
@ -37,16 +30,15 @@ OFF will switch off the Othelo game. When Othelo is restarted from the menu,
ON will suspend the current Othelo game. When Othelo is restarted from the
menu, play will continue from where it left off.
Either player may be a Human or Computer, and this may be changed at any time
during play with F1 and F2. The current choice is indicated by an H or C
above the respective F1 and F2 buttons on the Jukebox.
Either player may be a Human or Computer, and this may be changed at any time during play with F1 and F2. The current choice is indicated by an H or C above the respective F1 and F2 buttons on the Jukebox.
NOTE: The "suspend" function relied on an 'undocumented' feature which is no longer prevelant under the new "plugin" system. Therefore it needs to be re-implemented as "save progress to file." There are a number of reasons why this has not been implemented - if there is any demand for it, it will be added.
Computer Advice
===============
When a Human is playing, he may select any of the AI Bots to offer advice (it
is described as the Computer "dreaming" for you).
When a Human is playing, he may select any of the AI Bots to offer advice (it is described as the Computer "dreaming" for you).
The default advice/help level is 0 (zero) ...no advice
Bot 1 help will simply highlight all possible valid moves
@ -54,37 +46,25 @@ Bot 2 will advise you which moves would steal the most pieces per turn
Bot 3 will offer even deeper insights about strategic positioning
Bot 4 hasn't been written yet ...watch this space
In each case a 'valid' move is displayed as a dot in the centre of the square
and a 'choice' move is highlighted with a cross.
In each case a 'valid' move is displayed as a dot in the centre of the square and a 'choice' move is highlighted with a cross.
AI Opponents
===========
============
There are currently three AI opponents C-1, C-2 and C-3 respectively. Each
has it's own style of play. Losing against one of the opponents does not
necessarily mean that you will lose against another.
There are currently three AI opponents C-1, C-2 and C-3 respectively. Each has it's own style of play. Losing against one of the opponents does not necessarily mean that you will lose against another.
It can be interesting to set both opponents to Computer mode and watch them
play against each other.
It can be interesting to set both opponents to Computer mode and watch them play against each other.
Navigation
==========
During the turn of a Human, the up, down, left and right cursor keys navigate
the board highlight in a suspiciously expected manner the chosen square. When
the cursor is highlighting the square you wish to play in, press PLAY. If you
have chosen an invalid move, the board will flash and you will be expected to
try again.
During the turn of a Human, the up, down, left and right cursor keys navigate the board highlight in a suspiciously expected manner to the chosen square. When the cursor is highlighting the square you wish to play in, press PLAY. If you have chosen an invalid move, the board will flash and you will be expected to try again.
Button repeat _is_ enabled for navigation.
The AI opponents will pause slightly before making their move, to allow you to
see the result of your move. If you wish to force the Computer opponent to
wait longer before playing, you may keep PLAY depressed ("keep your finger on
the piece you just played") and the Computer will make his move immediately
you remove your finger from the keypad.
The AI opponents will pause slightly before making their move, to allow you to see the result of your move. If you wish to force the Computer opponent to wait longer before playing, you may keep PLAY depressed ("keep your finger on the piece you just played") and the Computer will make his move immediately you remove your finger from the keypad.
Display
@ -92,67 +72,44 @@ Display
The main board is that great big grid thing taking up most of the screen.
Above F1 and F2, on the bottom line of the screen, is the identity of each
player. Such as:
Above F1 and F2, on the bottom line of the screen, is the identity of each player. Such as:
"O:C-1" ...this means that, the player represented by the "O" graphic is a
[C]omputer and is controlled by AI Bot #1
"O:H-2" ...this means that, the player represented by the "O" graphic is a
[H]uman player, and has AI Bot #0 dreaming for him
[H]uman player, and has AI Bot #2 dreaming for him
etc.
The scores are shown toward the bottom right of the screen and the current
player has a small arrow (->) next to his name, indicating that he should
hurry up and actually make a move, today preferably ...although if the music
does run out, you can always use the ON button to suspend the game while you
go and queue up some more :)
The scores are shown toward the bottom right of the screen and the current player has a small arrow (->) next to his name, indicating that he should hurry up and actually make a move, today preferably ...although if the music does run out, you can always use the ON button to suspend the game while you go and queue up some more :) ...or not if you are using the current plugin version :(
During play the rest of the screen (the big lump on the right at the top) will
show a pointless graphic to make the screen look pretty. When the game is
quit or finished naturally, this area will display the identity of the winner,
and a secret "end of play" message.
During play the rest of the screen (the big lump on the right at the top) will show a pointless graphic to make the screen look pretty. When the game is quit or finished naturally, this area will display the identity of the winner, and a secret "end of play" message.
Source Code
===========
The source code is scruffy, but well documented.
The source code is scruffy, but well documented. For the plugin system all headers files were included into the main source code and erased to conform to the new coding standard.
Future Development
==================
Better AI Bots. A perfect AI Bot is easy and you can add tolerances to it
from there (to dumb it down a bit) ...the dilemma is the vast quantity of RAM
required to run it. So the Bots really need to be strategy and not logic
based.
Better AI Bots. A perfect AI Bot is easy and you can add tolerances to it from there (to dumb it down a bit) ...the dilemma is the vast quantity of RAM required to run it. So the Bots really need to be strategy and not logic based.
Remote control support. Save wear and tear on your Jukebox keys - that really
weren't designed with games players in mind.
Tidy code to conform to whatever complaints I get about it.
Remote control support. Save wear and tear on your Jukebox keys - that really weren't designed with games players in mind.
Coding standards, bugs'n'stuff
==============================
Remember, if you don't like the code ...throw it away and never look at it
again! ...Please do not tell me, I don't care. Any complaint requiring a
response should be written on the back of notes valued at five thousand shiny
new pennies of the British realm.
Remember, if you don't like the code ...throw it away and never look at it again! ...Please do not tell me, I don't care. Any complaint requiring a response should be written on the back of notes valued at five thousand shiny new pennies of the British realm. ;)
On the other hand, I love getting compliments, I am pleased to hear about bugs
I can fix - although they don't tend to happen too often in my code ...go on
then find one! If you can think of any clever short cuts I have missed or
fancy your hand at writing the next AI Bot - gimme a shout and I will explain
all there is to know about possibility lists, and perhaps even answer such
questions as "why is there only one equals sign in this IF statement" and "why
are there lines of code with question marks in them"
On the other hand, I love getting compliments, I am pleased to hear about bugs I can fix - although they don't tend to happen too often in my code ...go on then, find one! If you can think of any clever short cuts I have missed or fancy your hand at writing the next AI Bot - gimme a shout and I will explain all there is to know about possibility lists, and perhaps even answer such questions as "why is there only one equals sign in this IF statement" and "why are there lines of code with question marks in them"
Greetz
======
mk, pajaco, Hardeep, DevZer0, jzoss, LinusN
mk, pajaco, DevZer0, jzoss, LinusN, Zagor, Cyborg, Lord Grumble
Author
@ -161,3 +118,5 @@ Author
BlueChip
Yep, the lot - and right chuffed with miself too :)
-- othelo.txt - EOF