The real easy solution is to simply check from the last move made ... it is obvious that no previous move could win the game, or you would not be here ... so you just need to check if there are 5 (or as many ) in the row / column / diagonal around the moved object.
For example, if the panel looks like this, and X marks the most recent move:
............. ............. ............. ............. .....X....... ............. ............. ............. ............. .............
You do not need to check anything outside the "C" range:
.C...C...C... ..C..C..C.... ...CCC.... ....CCC...... .CCCCXCCCC... ....CCC...... ...CCC.... ..C..C..C.... .C...C...C... .............
Does it help? (It looks like you could refer to this in your original question, but I was not sure.)
In addition, simple loops will become your best friend. You might be able to do some micro-optimization, but (depending on what your actual application is doing) this is probably not worth it.
One thing to keep in mind is that you cannot simply jump 5 in any direction from the very last move, looking for it a lot in a row, because this movement may be in the middle of the lane. So I would do something like
From the new move left = how many in a row we have to the left of the lastest move right = how many in a row we have to the right of the latest move if (left + right + 1 >= 5) then you have a winner up = how many in a row we have above the latest move down = how many in a row we have below the latest move if (up + down + 1 >= 5) then you have a winner // repeat for both diagonal directions.
Beska
source share