Improved Reversi - General Discussion and Assistance - CHDK Forum

Improved Reversi

  • 12 Replies
  • 7957 Views
Improved Reversi
« on: 28 / September / 2018, 06:58:01 »
Advertisements
Hey!  I'm new here.  But I've been messing with CHDK on my own for a while.  I've worked on improving the gui_reversi.c game to become familiar with game programming on the camera.

What I've done to it is:
* Removed the A...H and 1...8 position indicators
* Changed the board colors
* Increased the board size
* Removed (almost) all flicker
* Made the AI more interesting, and maybe smarter
* Cleaned up the source code

It also compiles to a smaller binary and runs faster.  I'd love if people would try it out and comment.  The code is at:

https://github.com/glurk/chdk-reversi

For anyone to try out.  I'm hoping to start on a "Checkers" game based on some of this work.  Any comments appreciated, thanks!

*

Offline srsa_4c

  • ******
  • 4451
Re: Improved Reversi
« Reply #1 on: 29 / September / 2018, 16:56:11 »
I'm okay with most of the changes, except for the following:
- The status display is not placed correctly on DIGIC 6 cameras (see attached screenshots). The overlay on these is either 640x480 or 720x480, when using the LCD. Unlike on previous cameras, the pixels are square.
  I'm not sure what would be the best way to support 640x480 - either shrink the grid or modify the arrangement of the status display.
- It would be preferable to avoid drawing in gui_reversi_kbd_process(). This function is called from the keyboard task (physw), usually 100 times per second.
  Drawing should take place in gui_reversi_draw() which is called from spytask at a much lower frequency. Physw and spytask are independent tasks, running in parallel.

Re: Improved Reversi
« Reply #2 on: 02 / October / 2018, 06:42:13 »
@srsa_4c

Thanks for the feedback.  I've implemented your suggestions but I only have a SD1000 (360x240) to work with.  Please take a look at my updated code on GitHub and see what you think.  Are 360x240, 640x480 and 720x480 the only possible resolutions, or are there others?

It appears that to do things "right" will require editing the language / translation files.  I don't know how to even try to do that...

Also, the AI is still work-in-progress and right now it's bad.  Working on it.  I tried to focus on fixing the display issues mostly.

Thanks for your time.

*

Offline srsa_4c

  • ******
  • 4451
Re: Improved Reversi
« Reply #3 on: 02 / October / 2018, 17:42:25 »
I've implemented your suggestions but I only have a SD1000 (360x240) to work with.  Please take a look at my updated code on GitHub and see what you think.
I think the reworked status display looks even better than the original. 
Quote
Are 360x240, 640x480 and 720x480 the only possible resolutions, or are there others?
IIRC, some older models may have a bit less horizontal resolution (352x240), but that should not be a problem with the current layout. There are a few models with a wide LCD, 480x240.
I think that's all. There are some newer models with different/higher resolution LCD (or EVF?), but those have not been ported. The overlay becomes significantly larger when a HDMI monitor is used, but I don't think anyone would want to play games like that.

Quote
It appears that to do things "right" will require editing the language / translation files.  I don't know how to even try to do that...
core/gui_lang.h, CHDK/lang/*.lng
You could probably reuse the string IDs that are no longer necessary (159, 160, 162). 161 should probably lose the padding spaces. The white and black strings can be copied from 162 for all languages. Alternatively, you could use actual colors rather than printing their names.

Re: Improved Reversi
« Reply #4 on: 30 / December / 2018, 05:04:12 »
Hey!  After some hiatus, I'm back.  Probably no-one cares about this dumb game, but I returned to it and got it in pretty good shape, I think.

What I've done to it now is:
* Fixed up the AI a bit more, maybe smarter
* Cleaned up the source code
* Replaced certain translation issues using graphics
* Made it work on all cameras, even DIGIC 6 (I think?)
* Left the translation files untouched(!)

The program no longer uses string ID's 159, 160, 161 and 162.  So these could be freed for other uses, I suppose.  If srsa_4c or anyone could give it a try, I'd appreciate it.  I'm not certain about D6, I have no way to test, but I could move graphic elements if needed.

The updated code is still at:

https://github.com/glurk/chdk-reversi

If anything looks wonky on D6 or any other camera, please post a screenshot and I will try to fix.  I'm pretty happy with this now, it was actually a bit of work...  The relative co-ordinate X/Y positioning is a big pain, LOL!

@srsa_4c - If this passes muster, how can I get this added to CHDK proper?  I think it's a decent improvement, so I'd like to have it added.  All credits to the original author, of course!

*

Offline srsa_4c

  • ******
  • 4451
Re: Improved Reversi
« Reply #5 on: 30 / December / 2018, 19:04:40 »
I tried it out and found the following.
On D6, there is one remaining issue which (IMO) is related to a calculation that uses a constant that isn't derived from character size. See attachment.
Again, IMO, the score / active color representation is slightly non-intuitive - there are 2 fixed boxes around the score and a third one shows which one is active. The source of the issue is that the background color matches one of the "player" colors (black) - I guess this is the reason you used a magenta box.
How about moving the score out of the player color box and using the same color for both score numbers?
edit: Another idea: you could use filled circles in the score display.

Once "finished", I'm not against adding this, but I'll need a nod from reyalp.
« Last Edit: 30 / December / 2018, 19:28:35 by srsa_4c »

*

Online reyalp

  • ******
  • 14126
Re: Improved Reversi
« Reply #6 on: 30 / December / 2018, 22:38:49 »
Once "finished", I'm not against adding this, but I'll need a nod from reyalp.
I haven't really looked at it up to now, but if you think it's OK, it's fine with me.

Quote
Again, IMO, the score / active color representation is slightly non-intuitive - there are 2 fixed boxes around the score and a third one shows which one is active. The source of the issue is that the background color matches one of the "player" colors (black) - I guess this is the reason you used a magenta box.
I agree, it's a bit odd. If a fill color is needed so the black does disappear on the black screen, on of the field colors might make sense.

Also, the computer player is fast enough you really only see it blink, so I'm not really sure an "active" player indicator is needed at all. If there were a 2 human player mode (where the code just enforced the rules instead of playing for one side), it would be needed.

A couple minor code comments:
1)
Code: [Select]
typedef unsigned int uchar;
seems a bit confusing. If the "Field" values need a typedef, I'd suggest using something like field_t. For thinks like coordinates and state values I'd just use regular ints.

2) The "static" is dropped from some of the functions. This doesn't actually matter much since everything is local to the module unless it appears in the module interface structures, but keeping the non-exported functions "static" makes it a little more obvious in the code.
Don't forget what the H stands for.

Re: Improved Reversi
« Reply #7 on: 04 / January / 2019, 06:13:10 »
I've implemented all of the suggestions @srsa_4c and @reyalp.
The code, as before, is at:

https://github.com/glurk/chdk-reversi

I'm not sure that I like it better, but there it is.  If only I could add SOUNDS.
(Question - any way to add user-defined sounds?)

This should work on all models, but I have no way to test.

I've really only done this for my own fun, since I like programming, and because I'd like to add my own new game to CHDK (which will not be checkers, now.)

Please test and let me know of any issues now, thanks!

*

Online reyalp

  • ******
  • 14126
Re: Improved Reversi
« Reply #8 on: 04 / January / 2019, 22:54:22 »
I'm not sure that I like it better, but there it is.  If only I could add SOUNDS.
(Question - any way to add user-defined sounds?)
Not currently, but it should be possible with reverse engineering if you want to try your hand at that.
Don't forget what the H stands for.

*

Offline srsa_4c

  • ******
  • 4451
Re: Improved Reversi
« Reply #9 on: 07 / January / 2019, 18:25:31 »
I found no UI issues with the newest revision.
However, my opinion is that giving a hint about the current player can sometimes be useful (first time users, for example). The original version does this, but not the most straightforward way (the user's name is displayed rather than its color).
The attached screenshot was made with the below mod included (I added an arrowhead symbol in front of the current player's score).
Code: [Select]
Index: gui_reversi.c
===================================================================
--- gui_reversi.c (revision 5)
+++ gui_reversi.c (working copy)
@@ -306,7 +306,22 @@
 //-------------------------------------------------------------------
 static void redraw() {
     uint x, y, mid;
+    char *plm1, *plm2;
 
+    if (InGame) {
+        if (CurrPlayer==FIELD_PLAYER1) {
+            plm1 = "\x10";
+            plm2 = " ";
+        }
+        else {
+            plm1 = " ";
+            plm2 = "\x10";
+        }
+    }
+    else {
+        plm1 = plm2 = " ";
+    }
+
     draw_rectangle(field_x+cell_size*xPos, field_y+cell_size*yPos, field_x+cell_size*(xPos+1),
                    field_y+cell_size*(yPos+1), MAKE_COLOR(COLOR_RED,COLOR_RED), RECT_BORDER1);
     x = camera_screen.disp_left+field_size, y = 40;
@@ -315,10 +330,12 @@
     draw_string(x, y-10, "REVERSI", MAKE_COLOR(COLOR_BLUE, COLOR_WHITE));
     sprintf(buf, " %d ", NumPl1);
     draw_string(x+FONT_WIDTH*(7-strlen(buf))/2, y+FONT_HEIGHT*2, buf, MAKE_COLOR(COLOR_BLUE, COLOR_WHITE));
+    draw_string(x, y+FONT_HEIGHT*2, plm1, MAKE_COLOR(COLOR_BLUE, COLOR_WHITE));
     draw_ellipse(x+FONT_WIDTH*1.5+(cell_size>>1), y+FONT_HEIGHT*3+(cell_size>>1),
                         (cell_size>>1)-4, (cell_size>>1)-4, COLOR_WHITE, DRAW_FILLED);
     sprintf(buf, " %d ", NumPl2);
     draw_string(x+FONT_WIDTH*(7-strlen(buf))/2, y+FONT_HEIGHT*6, buf, MAKE_COLOR(COLOR_BLUE, COLOR_WHITE));
+    draw_string(x, y+FONT_HEIGHT*6, plm2, MAKE_COLOR(COLOR_BLUE, COLOR_WHITE));
     draw_ellipse(x+FONT_WIDTH*1.5+(cell_size>>1), y+FONT_HEIGHT*7+(cell_size>>1),
                         (cell_size>>1)-4, (cell_size>>1)-4, COLOR_BLACK, DRAW_FILLED);
 }
Should this go in or the indicator-less version? Or, any better suggestions for the indicator?

 

Related Topics


SimplePortal © 2008-2014, SimplePortal