I am programming a game that is a rip of connect four for the GBA. The GBA isn't so fast. I'm not even done with my win-checking function and there is like a 1 sec slowdown when my program checks for a winner. If you don't know what connect four is read on, if you do, skip to the asterisks...anyway it's a game where you have a 7*6 board. There are two players, each with markers of different colors. You choose a column on the board and put your piece at the bottom of the column. If there is already a piece at the bottom you put your piece one space up from that piece. Whoever gets four of their pieces in a row horizontaly, vertically, or diagnaly first wins. I hope I did a good job of explaining...
Anyway, my board is stored in a 1d array. Each spot has a number. Here is a picture of my board where each number is a space:
So I loop about the board checking to see if there are four of the same colored pieces in a row. This is very, very slow. I have nested loops that check for four in a row horizontaly and vertically. I have a bunch of loops that check diagonal ascending to the rightand diagonal ascending to the left. I have hit major problems checking diagonaly since every other row is a different length than any other row, so I need to have like 10 loops to check diagonaly.Code:5 6 7 8 9 10 11 12 13 14 17 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
Am I going about this the wrong way?
I would be very, very grateful if someone could help me.