public void khoitaomangoco() { for (int i = 0; i <= ban_Co.Sodong; i++) { for (int j = 0; j <= ban_Co.SoCot; j++) { _arrayChess[i, j] = new Oco(i, j, new Point(j * Oco._chieuRong + 15, i * Oco._chieuCao + 15), 0); } } }
private void panel_co_ganh_MouseClick(object sender, MouseEventArgs e) { int currentcot = e.X / (Oco._chieuRong); int currnetdong = e.Y / (Oco._chieuCao); int currensohuu = 0; clearnList(); list.Clear(); listQuanKeNhau.Clear(); List <Oco> kiemtradoc = new List <Oco>(); List <Oco> kiemtranghang = new List <Oco>(); List <Oco> kiemtracheonguoc = new List <Oco>(); List <Oco> kiemtracheoxuoi = new List <Oco>(); if (!danhco) { for (int row = 0; row < listquanco.Count; row++) { layViTri(row, currnetdong, currentcot); } } else { for (int row = 0; row < listquanco.Count; row++) { if (listquanco[row].Dong == currnetdong && listquanco[row].Cot == currentcot) { currensohuu = listquanco[row].Sohuu; } } if (check.cothedichuyen(lastDong, lastcot, currnetdong, currentcot, currensohuu)) { for (int row = 0; row < listquanco.Count; row++) { if (listquanco[row].Dong == lastDong && listquanco[row].Cot == lastcot) { listquanco.RemoveAt(row); _arrayChess[lastDong, lastcot].Sohuu = 0; DanhCo(e.X, e.Y, graphics, lastsohuu); kiemtradoc = kiemtraDoc(listquanco, currnetdong, currentcot, lastsohuu); kiemtranghang = kiemtraNgang(listquanco, currnetdong, currentcot, lastsohuu); kiemtracheoxuoi = kiemTraCheoXuoi(listquanco, currnetdong, currentcot, lastsohuu); kiemtracheonguoc = kiemTraCheoNguoc(listquanco, currnetdong, currentcot, lastsohuu); } } } if (kiemtradoc.Count == 2) { for (int i = 0; i < kiemtradoc.Count; i++) { kiemtradoc[i].Sohuu = lastsohuu; luotdi = lastsohuu; } } if (kiemtranghang.Count == 2) { for (int i = 0; i < 2; i++) { kiemtranghang[i].Sohuu = lastsohuu; luotdi = lastsohuu; } } if (kiemtracheonguoc.Count == 2) { for (int i = 0; i < 2; i++) { kiemtracheonguoc[i].Sohuu = lastsohuu; luotdi = lastsohuu; } } if (kiemtracheoxuoi.Count == 2) { for (int i = 0; i < 2; i++) { kiemtracheoxuoi[i].Sohuu = lastsohuu; luotdi = lastsohuu; } } for (int row = 0; row < listquanco.Count; row++) { if (listquanco[row].Dong == currnetdong && listquanco[row].Cot == currentcot) { for (int i = 0; i < listquanco.Count; i++) { kiemtraHetnuoc(i, currnetdong, currentcot); } } } clearnList(); for (int item = 0; item < list.Count; item++) { kiemtradoc = new List <Oco>(); kiemtranghang = new List <Oco>(); kiemtracheoxuoi = new List <Oco>(); kiemtracheonguoc = new List <Oco>(); if (list[item].Dong > 0 && list[item].Dong < ban_Co.Sodong && list[item].Cot > 0 && list[item].Cot < ban_Co.SoCot) { kiemtradoc = kiemtraDoc(listquanco, currnetdong, currentcot, list[item].Sohuu); kiemtranghang = kiemtraNgang(listquanco, currnetdong, currentcot, list[item].Sohuu); kiemtracheoxuoi = kiemTraCheoXuoi(listquanco, currnetdong, currentcot, list[item].Sohuu); kiemtracheonguoc = kiemTraCheoNguoc(listquanco, currnetdong, currentcot, list[item].Sohuu); if (kiemtradoc.Count == 2 && kiemtranghang.Count == 2 && kiemtracheoxuoi.Count == 0 && kiemtracheonguoc.Count == 0) { for (int i = 0; i < listquanco.Count; i++) { if (listquanco[i].Dong == list[item].Dong && listquanco[i].Cot == list[item].Cot) { if (list[item].Sohuu == 1) { listquanco[i].Sohuu = 2; } else { listquanco[i].Sohuu = 1; } } } } else { if (kiemtradoc.Count == 2 && kiemtranghang.Count == 2 && kiemtracheonguoc.Count == 2 && kiemtracheoxuoi.Count == 0) { for (int i = 0; i < listquanco.Count; i++) { if (listquanco[i].Dong == list[item].Dong && listquanco[i].Cot == list[item].Cot) { if (list[item].Sohuu == 1) { listquanco[i].Sohuu = 2; } else { listquanco[i].Sohuu = 1; } } } } else { if (kiemtradoc.Count == 2 && kiemtranghang.Count == 2 && kiemtracheonguoc.Count == 2 && kiemtracheoxuoi.Count == 2) { for (int i = 0; i < listquanco.Count; i++) { if (listquanco[i].Dong == list[item].Dong && listquanco[i].Cot == list[item].Cot) { if (list[item].Sohuu == 1) { listquanco[i].Sohuu = 2; } else { listquanco[i].Sohuu = 1; } } } } } } } if (list[item].Dong == 0 || list[item].Dong == ban_Co.Sodong) { kiemtradoc = kiemtraDoc(listquanco, list[item].Dong, list[item].Cot, list[item].Sohuu); kiemtranghang = kiemtraNgang(listquanco, list[item].Dong, list[item].Cot, list[item].Sohuu); kiemtracheoxuoi = kiemTraCheoXuoi(listquanco, list[item].Dong, list[item].Cot, list[item].Sohuu); kiemtracheonguoc = kiemTraCheoNguoc(listquanco, list[item].Dong, list[item].Cot, list[item].Sohuu); if (kiemtradoc.Count == 1 && kiemtranghang.Count == 2) { for (int i = 0; i < listquanco.Count; i++) { if (listquanco[i].Dong == list[item].Dong && listquanco[i].Cot == list[item].Cot) { if (list[item].Sohuu == 1) { listquanco[i].Sohuu = 2; } else { listquanco[i].Sohuu = 1; } } } } } if (list[item].Cot == 0 || list[item].Cot == ban_Co.SoCot) { kiemtradoc = kiemtraDoc(listquanco, list[item].Dong, list[item].Cot, list[item].Sohuu); kiemtranghang = kiemtraNgang(listquanco, list[item].Dong, list[item].Cot, list[item].Sohuu); kiemtracheoxuoi = kiemTraCheoXuoi(listquanco, list[item].Dong, list[item].Cot, list[item].Sohuu); kiemtracheonguoc = kiemTraCheoNguoc(listquanco, list[item].Dong, list[item].Cot, list[item].Sohuu); if (kiemtradoc.Count == 2 && kiemtranghang.Count == 1) { for (int i = 0; i < listquanco.Count; i++) { if (listquanco[i].Dong == list[item].Dong && listquanco[i].Cot == list[item].Cot) { if (list[item].Sohuu == 1) { listquanco[i].Sohuu = 2; } else { listquanco[i].Sohuu = 1; } } } } } clearnList(); if (list[item].Dong == 0 && (list[item].Cot == 0 || list[item].Cot == ban_Co.SoCot)) { kiemtradoc = kiemtraDoc(listquanco, list[item].Dong, list[item].Cot, list[item].Sohuu); kiemtranghang = kiemtraNgang(listquanco, list[item].Dong, list[item].Cot, list[item].Sohuu); kiemtracheoxuoi = kiemTraCheoXuoi(listquanco, list[item].Dong, list[item].Cot, list[item].Sohuu); kiemtracheonguoc = kiemTraCheoNguoc(listquanco, list[item].Dong, list[item].Cot, list[item].Sohuu); if (kiemtradoc.Count == 1 && kiemtranghang.Count == 1 && (kiemtracheoxuoi.Count == 1 || kiemtracheonguoc.Count == 1)) { for (int i = 0; i < listquanco.Count; i++) { if (listquanco[i].Dong == list[item].Dong && listquanco[i].Cot == list[item].Cot) { if (list[item].Sohuu == 1) { listquanco[i].Sohuu = 2; } else { listquanco[i].Sohuu = 1; } } } } } if (list[item].Dong == ban_Co.Sodong && (list[item].Cot == 0 || list[item].Cot == ban_Co.SoCot)) { kiemtradoc = kiemtraDoc(listquanco, list[item].Dong, list[item].Cot, list[item].Sohuu); kiemtranghang = kiemtraNgang(listquanco, list[item].Dong, list[item].Cot, list[item].Sohuu); kiemtracheoxuoi = kiemTraCheoXuoi(listquanco, list[item].Dong, list[item].Cot, list[item].Sohuu); kiemtracheonguoc = kiemTraCheoNguoc(listquanco, list[item].Dong, list[item].Cot, list[item].Sohuu); if (kiemtradoc.Count == 1 && kiemtranghang.Count == 1 && (kiemtracheoxuoi.Count == 1 || kiemtracheonguoc.Count == 1)) { for (int i = 0; i < listquanco.Count; i++) { if (listquanco[i].Dong == list[item].Dong && listquanco[i].Cot == list[item].Cot) { if (list[item].Sohuu == 1) { listquanco[i].Sohuu = 2; } else { listquanco[i].Sohuu = 1; } } } } } } for (int item = 0; item < list.Count - 1; item++) { for (int j = item + 1; j < list.Count; j++) { if ((list[item].Dong == list[j].Dong && list[item].Cot > list[j].Cot) || (list[item].Dong > list[j].Dong && list[item].Cot == list[j].Cot) || (list[item].Dong > list[j].Dong && list[item].Cot > list[j].Cot)) { Oco arr = list[item]; list[item] = list[j]; list[j] = arr; } } } List <Oco> abc = new List <Oco>(); if (list.Count == 2) { for (int item = 0; item < list.Count - 1; item++) { if (list[item].Dong == list[item + 1].Dong || list[item].Cot == list[item + 1].Cot) { abc.Add(list[item]); abc.Add(list[item + 1]); } } } Oco asdasd = findBestMove(_arrayChess); Console.WriteLine(" lay dong " + asdasd.Dong); Console.WriteLine(" lay cot " + asdasd.Cot); graphics.Clear(panel_co_ganh.BackColor); ban_Co.banco(graphics); velaiquanco(graphics); kiemtrasoquan(); danhco = false; luotdis(); } }