private void CheckTRBL() { int pos = -1; List <AvailableBlock> blks = new List <AvailableBlock>(); AvailableBlock blk = new AvailableBlock(); base.TopRightBottomLeftCheck((x, y, lineNr) => { Check(x, y, lineNr, ref pos, ref blk, blks); return(false); }); if (blk.X >= 0 && (blk.PlayerRateX > 0 || blk.PlayerRateO > 0)) { blks.Add(blk); } foreach (AvailableBlocksMap bs in blocks) { for (int i = blks.Count - 1; i >= 0; i--) { if (bs.X == blks[i].X && bs.Y == blks[i].Y) { bs.TopRightBottomLeft.O += blks[i].PlayerRateO; bs.TopRightBottomLeft.X += blks[i].PlayerRateX; blks.RemoveAt(i); } } } if (blks.Count > 0) { foreach (AvailableBlock b in blks) { AvailableBlocksMap abm = new AvailableBlocksMap(b.X, b.Y); abm.TopRightBottomLeft.X = b.PlayerRateX; abm.TopRightBottomLeft.O = b.PlayerRateO; blocks.Add(abm); } } }
private void Check(int x, int y, int lineNr, ref int pos, ref AvailableBlock blk, List <AvailableBlock> blks) { if (lineNr != pos) { if (blk.X >= 0 && (blk.PlayerRateX > 0 || blk.PlayerRateO > 0)) { blks.Add(blk); blk = new AvailableBlock(); } else { blk.SetDefault(); } pos = lineNr; } if (map[x, y] == Player.NONE) { if (blk.SelectedPlayer == Player.NONE) { if (blk.PlayerRateX > 0 || blk.PlayerRateO > 0) { blks.Add(blk); blk = new AvailableBlock(x, y); } else { blk.SetDefault(x, y); } } else if (blk.SelectedPlayer == Player.X) { if (blk.X >= 0) { if (blk.PlayerRateX > 0 || blk.PlayerRateO > 0) { blks.Add(blk); blk = new AvailableBlock(x, y, blk.PlayerRateX); } } else { blk.SetDefault(x, y, blk.PlayerRateX); } } else if (blk.SelectedPlayer == Player.O) { if (blk.X >= 0) { if (blk.PlayerRateX > 0 || blk.PlayerRateO > 0) { blks.Add(blk); blk = new AvailableBlock(x, y, 0, blk.PlayerRateO); } } else { blk.SetDefault(x, y, 0, blk.PlayerRateO); } } } else if (map[x, y] == Player.X) { if (blk.SelectedPlayer == Player.O) { if (blk.X >= 0) { if (blk.PlayerRateX > 0 || blk.PlayerRateO > 0) { blks.Add(blk); } blk = new AvailableBlock(); } else { blk.SetDefault(); } } blk.SelectedPlayer = Player.X; blk.PlayerRateX++; } else if (map[x, y] == Player.O) { if (blk.SelectedPlayer == Player.X) { if (blk.X >= 0) { if (blk.PlayerRateX > 0 || blk.PlayerRateO > 0) { blks.Add(blk); } blk = new AvailableBlock(); } else { blk.SetDefault(); } } blk.SelectedPlayer = Player.O; blk.PlayerRateO++; } }