public void mangoco() { for (int i = 0; i < Banco.Sodong; i++) { for (int j = 0; j < Banco.Socot; j++) { Mangoco[i, j] = new oCo(i, j, new Point(j * oCo.chieurong, i * oCo.chieucao), 0); } } }
public void KhoidongPC(Graphics g) { if (Luocdi == 1) { //đánh giữa bàn cờ if (stackCacnuocdadi.Count == 0) { danhco(Banco.Sodong / 2 * oCo.chieucao + 1, Banco.Socot / 2 * oCo.chieurong + 1, g); } else { oCo oco = _timnuocdi(); danhco(oco.Vitri.X + 1, oco.Vitri.Y + 1, g); } } }
public void Redo(Graphics g) { if (stacknuocundo.Count != 0) { oCo oco = stacknuocundo.Pop(); //stack chua cac nuoc da di stackCacnuocdadi.Push(new oCo(oco.Dong, oco.Cot, oco.Vitri, oco.Sohuu)); Mangoco[oco.Dong, oco.Cot].Sohuu = oco.Sohuu; Banco.vequanco(g, oco.Vitri, oco.Sohuu == 1 ? sbblue : sbred); } if (Luocdi == 1) { Luocdi = 2; } else { Luocdi = 1; } }
public bool danhco(int MouseX, int MouseY, Graphics g) { if (MouseX % oCo.chieurong == 0 || MouseY % oCo.chieucao == 0) { return(false); } int Cot = MouseX / oCo.chieurong; int Dong = MouseY / oCo.chieucao; //kiểm soát không cho vẽ đè lên if (Mangoco[Dong, Cot].Sohuu != 0) { return(false); } //thay phiên với nhau đánh switch (Luocdi) { case 1: Mangoco[Dong, Cot].Sohuu = 1; Banco.vequanco(g, Mangoco[Dong, Cot].Vitri, sbblue); Luocdi = 2; break; case 2: Mangoco[Dong, Cot].Sohuu = 2; Banco.vequanco(g, Mangoco[Dong, Cot].Vitri, sbred); Luocdi = 1; break; default: MessageBox.Show("Đi Lỗi"); break; } stacknuocundo = new Stack <oCo>(); oCo oco = new oCo(Mangoco[Dong, Cot].Dong, Mangoco[Dong, Cot].Cot, Mangoco[Dong, Cot].Vitri, Mangoco[Dong, Cot].Sohuu); stackCacnuocdadi.Push(oco); return(true); }
//tạo hàm AI cho máy private oCo _timnuocdi() { oCo ocoresult = new oCo(); long diemmax = 0; for (int i = 0; i < Banco.Sodong; i++) { for (int j = 0; j < Banco.Socot; j++) { if (Mangoco[i, j].Sohuu == 0) { long diemtancong = DTC_DuyetDoc(i, j) + DTC_DuyetNgang(i, j) + DTC_DuyetCheoXuoi(i, j) + DTC_DuyetCheoNguoc(i, j); long diemphongngu = DPN_DuyetDoc(i, j) + DPN_DuyetNgang(i, j) + DPN_DuyetCheoXuoi(i, j) + DPN_DuyetCheoNguoc(i, j); long diemtam = diemtancong > diemphongngu ? diemtancong : diemphongngu; if (diemmax < diemtam) { diemmax = diemtam; ocoresult = new oCo(Mangoco[i, j].Dong, Mangoco[i, j].Cot, Mangoco[i, j].Vitri, Mangoco[i, j].Sohuu); } } } } return(ocoresult); }
public void undo(Graphics g) { if (stackCacnuocdadi.Count != 0) { oCo oco = stackCacnuocdadi.Pop(); //stack chua cac nuoc da undo stacknuocundo.Push(new oCo(oco.Dong, oco.Cot, oco.Vitri, oco.Sohuu)); Mangoco[oco.Dong, oco.Cot].Sohuu = 0; Banco.xoaquanco(g, oco.Vitri, sbYellow); oCo oco2 = stackCacnuocdadi.Pop(); //stack chua cac nuoc da undo stacknuocundo.Push(new oCo(oco2.Dong, oco2.Cot, oco2.Vitri, oco2.Sohuu)); Mangoco[oco.Dong, oco.Cot].Sohuu = 0; Banco.xoaquanco(g, oco.Vitri, sbYellow); } if (Luocdi == 1) { Luocdi = 2; } else { Luocdi = 1; } }