algorithm to check a connect four field

前端 未结 3 1232
礼貌的吻别
礼貌的吻别 2020-11-30 00:43

I\'m wondering what\'s the best way to check for a winner on a connect four field.

I\'m interested in what you guys think and whether there is some \"well-known\" al

3条回答
  •  醉梦人生
    2020-11-30 01:16

    Each cell can only attribute to a maximum number of 12 winning combinations. (4 horizontal, 4 vertical and 4 diagonal). Each combination would have 4 cells including the one under consideration. And these numbers are going to be much lower for the cells closer to the sides. So it would make sense to pre-compile these combinations and store a hash of hash of related cells which can make a single play a winner. This way after each cell is player you simply pull out the related combinations/cells to check if it's a winner.

提交回复
热议问题