- Status Closed
- Percent Complete
- Task Type Patches
- Category Plugins
- Assigned To No-one
- Operating System
- Severity Low
- Priority Very Low
- Reported Version
- Due in Version Undecided
-
Due Date
Undecided
- Votes
- Private
FS#1551 - nim game for the player (clean version) v1.1
Ooops…. This file replace the precedent file
This is a true version of the game with a clean definition
of the patterns
Nim game V1.1
Pierre Delore
delorepierre@free.fr
Loading...
Available keyboard shortcuts
- Alt + ⇧ Shift + l Login Dialog / Logout
- Alt + ⇧ Shift + a Add new task
- Alt + ⇧ Shift + m My searches
- Alt + ⇧ Shift + t focus taskid search
Tasklist
- o open selected task
- j move cursor down
- k move cursor up
Task Details
- n Next task
- p Previous task
- Alt + ⇧ Shift + e ↵ Enter Edit this task
- Alt + ⇧ Shift + w watch task
- Alt + ⇧ Shift + y Close Task
Task Editing
- Alt + ⇧ Shift + s save task
i compiled this rock for my player and noticed some 2 bugs
on it.
1. when you play 1,3,9 it will make the sticks equal 0 and
you should lose but it goes on and goes to -1 sticks making
everything impossible. So I fixed that error.
2. When it does go to the negative numbers you can not push
stop to exit the plugin, you had to hold it down and reboot,
so i fixed that also
3. I got confused by the I wins, so i changed it to you win,
and bumped the version to 1.2
/* * _. * Open \ \ | | _\_ |
*/
static unsigned char cry[] ={0×00, 0×11, 0×04, 0×04, 0×00,
*/
static unsigned char pattern3[]={0×15, 0×15, 0×15, 0×15,
*/
rb = api;
/*Get the pattern handle*/
h1=rb→lcd_get_locked_pattern();
h2=rb→lcd_get_locked_pattern();
hcry=rb→lcd_get_locked_pattern();
hsmile=rb→lcd_get_locked_pattern();
exit=false;
rb→splash(HZ, 0, true, “NIM V1.2”);
rb→lcd_clear_display();
while(!exit)
{
/* Init */
x=21;
v=1;
y=1;
end=false;
min=0;
/*Empty the event queue*/
while (rb→button_get(false)!=BUTTON_NONE);
/*Affichage*/
while(end!=true)
{
do
{
ok=1;
y=1;
display_first_line(x);
_ _ * Source | _ _ \_/ _\| |/ /| \ / _ \
\/ / * Jukebox | | ( <_> ) \_| < | \_\ ( <_> >
< < * Firmware ||_ /\/ \_ >|_ \|_
/\/__/\_ \ * \/ \/ \/ \/
\/ * $Id: nim.c,v 1.2 2003/07/22 19:00:00 delore Exp $ * * Copyright (C) 2003 Pierre Delore * * 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. * / #include “plugin.h” #ifdef HAVE_LCD_CHARCELLS /* NIM game for the player Rules of nim game —————– There are 21 matches. Two players (you and the cpu) alternately pick a certain
number of matches and the one, who takes the last match, loses. */ /*Pattern for the game*/ static unsigned char smile[]={0×00, 0×11, 0×04, 0×04, 0×00,
0×11, 0x0E}; /*
0x0E, 0×11}; /*
0×15, 0×15, 0×15}; /*3 parts*/ static unsigned char pattern2[]={0×14, 0×14, 0×14, 0×14,
0×14, 0×14, 0×14}; /*2 parts*/ static unsigned char pattern1[]={0×10, 0×10, 0×10, 0×10,
0×10, 0×10, 0×10}; /*1 part*/ static unsigned char str[12]; /*String use to display the
first line*/ static unsigned char hsmile,hcry,h1,h2; /*Handle for the new
pattern*/ static bool end; /*If true game is finished*/ static struct plugin_api* rb; /*Display that the action it’s impossible*/ static void impossible(void) { rb→lcd_puts(0,1,”Impossible!”); rb→sleep(HZ); return; } /*Display that dthe CPU lose :) */ static void lose(void) { rb→lcd_define_pattern(hsmile,smile); rb→snprintf(str,sizeof(str),”You Win!! %c”,hsmile); rb→lcd_puts(0,1,str); end=true; rb→sleep(HZ*2); return; } /* Display that the CPU win :( */ static void win(void) { rb→lcd_define_pattern(hcry,cry); rb→snprintf(str,sizeof(str),”You Lose!! %c”,hcry); rb→lcd_puts(0,1,str); end=true; rb→sleep(HZ*2); return; } /*Display the first line*/ static void display_first_line(int x) { int i; rb→snprintf(str,sizeof(str),” =%d”,x); rb→lcd_define_pattern(h1,pattern3); for(i=0;i<x/3;i++) str[i]=h1; if (x%3==2) { rb→lcd_define_pattern(h2,pattern2); str[i]=h2; } if (x%3==1) { rb→lcd_define_pattern(h2,pattern1); str[i]=h2; } rb→lcd_puts(0,0,str); } /* Call when the program end */ static void nim_exit(void) { Restore the old pattern (i don’t find another way to
do this. An idea?) rb→lcd_unlock_pattern(h1); rb→lcd_unlock_pattern(h2); rb→lcd_unlock_pattern(hsmile); rb→lcd_unlock_pattern(hcry); //Clear the screen rb→lcd_clear_display(); } /* this is the plugin entry point */ enum plugin_status plugin_start(struct plugin_api* api,
void* parameter) { int y,z,button; int x,v,min; bool ok; bool go; bool exit; /* this macro should be called as the first thing you do
in the plugin. it test that the api version and model the plugin was
compiled for matches the machine it is running on */ TEST_PLUGIN_API(api); /* if you don’t use the parameter, you can do like this to avoid the compiler warning about it */ (void)parameter; /* if you are using a global api pointer, don’t forget
to copy it! otherwise you will get lovely “I04: IllInstr” errors…
rb→snprintf(str,sizeof(str),”[%d..%d]?=%d”,min,v,y); rb→lcd_puts(0,1,str); go=false; while (!go) { button = rb→button_get(true); switch ( button ) { case BUTTON_STOP|BUTTON_REL: exit = true; go = true;
nim_exit();
return PLUGIN_OK; break; case BUTTON_PLAY|BUTTON_REL: go=true; break; case BUTTON_LEFT|BUTTON_REL: go=false; if (y>min) y–; break; case BUTTON_RIGHT|BUTTON_REL: go=false; if (y<v) y++; break; case SYS_USB_CONNECTED: rb→usb_screen(); nim_exit(); return PLUGIN_USB_CONNECTED; } display_first_line(x);
rb→snprintf(str,sizeof(str),”[%d..%d]?=%d”,min,v,y); rb→lcd_puts(0,1,str); } if ( (y==0) && (x<21)) { impossible(); ok=false; } else { if (y!=0) /*Si y=0 et x=21 on saute a CPU*/ { if 1) { impossible(); ok=false; }
if (y-x==0)
{
win();
} else { v=y*2; x-=y; if (x<21) min=1; } } } } while (ok==false); if (exit) break; display_first_line(x); /*CPU*/ if (x==1) lose(); else if (x==2) win(); y=0; if (end==false) { for (z=v;z>=1;z–) { if (x-z==1) y=z; } if (y⇐0) { for(z=v;z>=1;z–) { if(x-(z*3)==2) y=z; } if 2) y=v; if (y==0) y=1; } v=y*2; x-=y; rb→snprintf(str,sizeof(str),”I take=%d”,y); rb→lcd_puts(0,1,str); rb→sleep(HZ); } if 3) win(); } } nim_exit(); return PLUGIN_OK; } #endif ————————— jorbond
JorBond2000@yahoo.com