My approach was to use the last move as the starting point, and check in all four directions. Since winner counter can be in the middle of a set of four, we have to check both ways.
Rather than a simple win, I decided to return a list of matching cells, so we can then store the result and change the UI to show the winning set of four. I added a .winner css class to highlight the winning cells. I don't think this is the best way - probably adding a Winner property to GamePiece and setting the CSS that way would be better.
I added a Position class as my code initially had a lot of (int x, int y) parameters being passed around and it made more sense. I also amended the PieceClicked method to check the column.
Thank you so much for contributing to this project! Unfortunately I've decided to go with the other implementation for finding a winner in Connect Four. Hope to hear from you again!
My approach was to use the last move as the starting point, and check in all four directions. Since winner counter can be in the middle of a set of four, we have to check both ways.
Rather than a simple win, I decided to return a list of matching cells, so we can then store the result and change the UI to show the winning set of four. I added a
.winner
css class to highlight the winning cells. I don't think this is the best way - probably adding aWinner
property toGamePiece
and setting the CSS that way would be better.I added a
Position
class as my code initially had a lot of(int x, int y)
parameters being passed around and it made more sense. I also amended thePieceClicked
method to check the column.