Bug in Connect4? - CHDK Releases - CHDK Forum

Bug in Connect4?

  • 6 Replies
  • 3643 Views
Bug in Connect4?
« on: 15 / July / 2017, 17:41:53 »
Advertisements
Hi everyone, haven't updated in a while, but the last builds I've tried all have a bug in the 4 in line game: it won't let the player play on the top row, and sometimes it leaves the AI green token displayed on top of the grid when it's your turn.
It doesn't affect the camera much, but I like my connect 4 game when I get bored, and I've been frustrating losing some games just because it won't let me do legal moves :haha
Anyway, apart from that, really happy, so thanks for all the hard work.

*

Offline reyalp

  • ******
  • 14125
Re: Bug in Connect4?
« Reply #1 on: 15 / July / 2017, 18:44:08 »
What camera and CHDK version are you using?

Do you have any idea what the version that worked was?
Don't forget what the H stands for.

Re: Bug in Connect4?
« Reply #2 on: 16 / July / 2017, 06:22:39 »
Hi Reyalp,
I'm using this file:
sx30-100e-1.4.1-4864-full.zip

The build that was working was a year old or more. I've tried few builds over the last few weeks and they all have the same problem, so the bug must have been there for quite a while.

I tried to go through the changelog to find out if anything was changed relating to the games but couldn't find any mention of it.

I guess I could try an official release and see if that works.

*EDIT* I tried build 4877 and still the same. At some point, the CPU even played on top of one of my tokens (so I started but he ended up having 14 tokens on the board against my 12). It did let me play the top row, but only once towards the end of the game when I had no other/little choice.

I tried sx30-100e-1.5.0-4876-full.zip and its the same as well.
« Last Edit: 16 / July / 2017, 06:31:51 by Cricri »

*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: Bug in Connect4?
« Reply #3 on: 16 / July / 2017, 07:46:47 »
This should be fixed in both 1.4 & 1.5 versions.


Looks like a compiler bug - the test for 'i<=6' on line 74 was being optimised out of the code for some reason.


Phil.

CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)
  g5x (1.00c, 1.01a, 1.01b)
  g7x2 (1.01a, 1.01b, 1.10b)

Re: Bug in Connect4?
« Reply #4 on: 16 / July / 2017, 08:47:21 »
Yay, it's fixed in 4880, thanks!  :D

*

Offline reyalp

  • ******
  • 14125
Re: Bug in Connect4?
« Reply #5 on: 16 / July / 2017, 14:56:03 »
Looks like a compiler bug - the test for 'i<=6' on line 74 was being optimised out of the code for some reason.
:o
If simple conditionals are being compiled wrong, that seems like a Bad Thing.
Don't forget what the H stands for.

*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: Bug in Connect4?
« Reply #6 on: 16 / July / 2017, 17:56:28 »
Looks like a compiler bug - the test for 'i<=6' on line 74 was being optimised out of the code for some reason.
:o
If simple conditionals are being compiled wrong, that seems like a Bad Thing.


Absolutely.


I didn't have time to explore thoroughly; but when I moved the test it worked and when I looked at the generated assembler the original code was not doing the test for i <= 6. Even putting brackets around the test did not work - I had to place it at the start of the test part of the for loop.


I haven't tried different compiler versions yet.

Edit: the original statement is problematic in itself,
Code: [Select]
    for(i=1; field[column-1][i] && i<=6; i++);
If the compiler generates code that tests the 'field' array value before the 'i' value (which most would), then when i == 7, an out-of-bounds array entry is being referenced.
Doesn't explain why the index test gets removed; but it needed fixing regardless.

Edit2:
ARM elf 4.4.3 - compiles correctly with the original code
ARM none-eabi 4.9.3 & 5.4.1 - removes the 'i<=6' test from the compiled code

Phil.
« Last Edit: 17 / July / 2017, 04:19:19 by philmoz »
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)
  g5x (1.00c, 1.01a, 1.01b)
  g7x2 (1.01a, 1.01b, 1.10b)

 

Related Topics


SimplePortal © 2008-2014, SimplePortal