exceptionnotfound / BlazorConnectFour

https://exceptionnotfound.net/learning-blazor-by-building-connect-four-in-asp-net-core/
8 stars 6 forks source link

Alternative implementation of the winning search algorithm. #2

Closed conficient closed 4 years ago

conficient commented 4 years ago

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.

exceptionnotfound commented 4 years ago

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!