exceptionnotfound / BlazorConnectFour

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

Additions to determine the winner. #1

Closed cambiaresearch closed 4 years ago

cambiaresearch commented 4 years ago

My approach for determining the winner might be a bit brute force, but I think it's intuitive. Thanks for the code and article.

conficient commented 4 years ago

I'd suggest a simpler approach than trying to brute-force checking every cell - just check the last move to see if that's a winning move.

By definition the winning move must be the last one (or we've missed a winning move!) - so rather than checking every cell in the board, just check for a row of four from the last one. Further to this you can skip the win check if the total number of moves made is less than 7.

I'd also suggest there are only three 'directions' to check: horizontal, vertical, diagonal. You would need to scan in each direction since a counter may have been dropped in the middle of a row.

conficient commented 4 years ago

Correction: having tried to write it myself there are indeed four directions, the diagonals are two separate "directions", I stand corrected