public ValidMoves(DifFigures f, int i, TakenPlaces Zafateni, bool[][] Enpassant) { Valid = new bool[8][]; for (int rr = 0; rr < 8; rr++) { Valid[rr] = new bool[8]; } figura = f; index = i; this.Zafateni = Zafateni; generatePotezi(f.t, i, f.White, Zafateni, Enpassant); IsEnpassant = false; Enpassant = new bool[2][]; Enpassant[1] = new bool[8]; Enpassant[0] = new bool[8]; }
private void button1_Click(object sender, EventArgs e) { String k = listBox1.Text; DifFigures zamena = new DifFigures(); zamena.White = this.White; if (!White) { if (String.Compare(k, "Кралица") == 0) { zamena.t = DifFigures.tip.Queen; f.figures[index].Image = Properties.Resources.Piece3; f.BlackTaken.Remove(DifFigures.tip.Queen); f.Ostanati[index].t = DifFigures.tip.Queen; f.removeItem1(DifFigures.tip.Queen); this.Close(); } else if (String.Compare(k, "Топ") == 0) { zamena.t = DifFigures.tip.Rook; f.figures[index].Image = Properties.Resources.Piece0; f.Ostanati[index].t = DifFigures.tip.Rook; f.BlackTaken.Remove(DifFigures.tip.Rook); f.removeItem1(DifFigures.tip.Rook); this.Close(); } else if (String.Compare(k, "Ловец") == 0) { zamena.t = DifFigures.tip.Bishop; f.Ostanati[index].t = DifFigures.tip.Bishop; f.figures[index].Image = Properties.Resources.Piece2; f.BlackTaken.Remove(DifFigures.tip.Bishop); f.removeItem1(DifFigures.tip.Bishop); this.Close(); } else if (String.Compare(k, "Коњ") == 0) { zamena.t = DifFigures.tip.Knight; f.Ostanati[index].t = DifFigures.tip.Knight; f.figures[index].Image = Properties.Resources.Piece1; f.BlackTaken.Remove(DifFigures.tip.Knight); f.removeItem1(DifFigures.tip.Knight); this.Close(); } else { this.Close(); } } else if (White) { if (String.Compare(k, "Кралица") == 0) { zamena.t = DifFigures.tip.Queen; f.Ostanati[index].t = DifFigures.tip.Queen; f.figures[index].Image = Properties.Resources.Piece59; f.removeItem2(DifFigures.tip.Queen); f.WhiteTaken.Remove(DifFigures.tip.Queen); this.Close(); } else if (String.Compare(k, "Топ") == 0) { zamena.t = DifFigures.tip.Rook; f.Ostanati[index].t = DifFigures.tip.Rook; f.figures[index].Image = Properties.Resources.Piece63; f.removeItem2(DifFigures.tip.Rook); f.WhiteTaken.Remove(DifFigures.tip.Rook); this.Close(); } else if (String.Compare(k, "Ловец") == 0) { zamena.t = DifFigures.tip.Bishop; f.Ostanati[index].t = DifFigures.tip.Bishop; f.figures[index].Image = Properties.Resources.Piece61; f.removeItem2(DifFigures.tip.Bishop); f.WhiteTaken.Remove(DifFigures.tip.Bishop); this.Close(); } else if (String.Compare(k, "Коњ") == 0) { zamena.t = DifFigures.tip.Knight; f.Ostanati[index].t = DifFigures.tip.Knight; f.figures[index].Image = Properties.Resources.Piece62; f.removeItem2(DifFigures.tip.Knight); f.WhiteTaken.Remove(DifFigures.tip.Knight); this.Close(); } else { this.Close(); } } }
public Form1() { InitializeComponent(); this.StartPosition = FormStartPosition.CenterScreen; startButton.BackColor = Color.FromArgb(255, 228, 225); textBox1.BackColor = Color.FromArgb(255, 250, 240); textBox2.BackColor = Color.FromArgb(255, 250, 240); BackColor = Color.FromArgb(255, 250, 240); menuStrip1.BackColor = Color.FromArgb(255, 250, 240); this.Icon = new System.Drawing.Icon(Properties.Resources.icon, new Size(20, 20)); this.MaximizeBox = false; this.MinimizeBox = false; Enpassant[0] = new bool[8]; // 0 za Napraven Castling, 1 za Mrdnat Kral, 2 i 3 za Mrdnati Topovi soodvetno (lev i desen) // 5 za Napraven Castling od strana na Crnite, 6 za Mrdnat Kral, 7 i 8 za Mrdnati Topovi soodvetno (lev i desen) for (int i = 0; i < 8; i++) { Castling[i] = true; } for (int i = 0; i < 2; i++) { Enpassant[i] = new bool[8]; for (int j = 0; j < 8; j++) { Enpassant[i][j] = new bool(); } } // Inicijaliziranje na Topovi Ostanati[0] = new DifFigures(); Ostanati[7] = new DifFigures(); Ostanati[56] = new DifFigures(); Ostanati[63] = new DifFigures(); Ostanati[56].t = DifFigures.tip.Rook; Ostanati[56].White = true; Ostanati[63].t = DifFigures.tip.Rook; Ostanati[63].White = true; Ostanati[0].t = DifFigures.tip.Rook; Ostanati[0].White = false; Ostanati[7].t = DifFigures.tip.Rook; Ostanati[7].White = false; // Inicijaliziranje na Konji Ostanati[1] = new DifFigures(); Ostanati[6] = new DifFigures(); Ostanati[57] = new DifFigures(); Ostanati[62] = new DifFigures(); Ostanati[1].t = DifFigures.tip.Knight; Ostanati[1].White = false; Ostanati[6].t = DifFigures.tip.Knight; Ostanati[6].White = false; Ostanati[57].t = DifFigures.tip.Knight; Ostanati[57].White = true; Ostanati[62].t = DifFigures.tip.Knight; Ostanati[62].White = true; //Inicijaliziranje na lamferi Ostanati[2] = new DifFigures(); Ostanati[5] = new DifFigures(); Ostanati[58] = new DifFigures(); Ostanati[61] = new DifFigures(); Ostanati[2].t = DifFigures.tip.Bishop; Ostanati[2].White = false; Ostanati[5].t = DifFigures.tip.Bishop; Ostanati[5].White = false; Ostanati[58].t = DifFigures.tip.Bishop; Ostanati[58].White = true; Ostanati[61].t = DifFigures.tip.Bishop; Ostanati[61].White = true; //Inicijaliziranje Kralici Ostanati[3] = new DifFigures(); Ostanati[59] = new DifFigures(); Ostanati[3].t = DifFigures.tip.Queen; Ostanati[3].White = false; Ostanati[59].t = DifFigures.tip.Queen; Ostanati[59].White = true; //Inicijaliziranje Kralovi Ostanati[4] = new DifFigures(); Ostanati[60] = new DifFigures(); Ostanati[4].t = DifFigures.tip.King; Ostanati[4].White = false; Ostanati[60].t = DifFigures.tip.King; Ostanati[60].White = true; for (int i = 16; i < 48; i++) { Ostanati[i] = new DifFigures(); Ostanati[i].White = false; Ostanati[i].t = DifFigures.tip.None; } for (int i = 8; i < 16; i++) { Ostanati[i] = new DifFigures(); Ostanati[i].t = DifFigures.tip.Pawn; Ostanati[i].White = false; } for (int i = 48; i < 56; i++) { Ostanati[i] = new DifFigures(); Ostanati[i].t = DifFigures.tip.Pawn; Ostanati[i].White = true; } for (int i = 56; i < 64; i++) { Ostanati[i].White = true; } int temp2 = 0; int temp = 10; for (int i = 0; i < 64; i++) { figures[i] = new PictureBox(); figures[i].SetBounds((i - temp2) * 50 + 10, temp, 30, 30); if (i % 8 == 7) { temp += 50; temp2 += 8; } figures[i].BackColor = Color.Transparent; this.Controls.Add(figures[i]); } for (int i = 0; i < 16; i++) { figures[i].Image = Properties.Resources.ResourceManager.GetObject("Piece" + i) as Image; figures[i].SizeMode = PictureBoxSizeMode.StretchImage; figures[i].BackColor = Color.Transparent; } for (int i = 48; i < 64; i++) { figures[i].Image = Properties.Resources.ResourceManager.GetObject("Piece" + i) as Image; figures[i].SizeMode = PictureBoxSizeMode.StretchImage; figures[i].BackColor = Color.Transparent; this.Controls.Add(figures[i]); } for (int i = 0; i < 32; i++) { Ostanati[i].White = false; } Ostanati[63].White = Ostanati[62].White = Ostanati[61].White = Ostanati[60].White = Ostanati[59].White = true; foreach (var p in figures) { p.MouseClick += this.figureHandlers; } }
void figureHandlers(object sender, EventArgs e) { PictureBox ptt = (PictureBox)sender; ValidMoves k = new ValidMoves(Ostanati[kliknato], kliknato, matrica, Enpassant); if (PlayerTurn[3]) { kliknato2 = Array.IndexOf(figures, ptt); if (kliknato2 == -1) { // Ако кликнеш надвор од шахот kliknato2 = 0; PlayerTurn[2] = true; PlayerTurn[3] = false; } else if (k.Zafateni.Whitte[kliknato2 / 8][kliknato2 % 8] == false) { // Ако се премислиш која фигура да ја поместиш PlayerTurn[2] = true; } if ((kliknato2 / 8 == 3 && Dva[0] / 8 == 1 && matrica.ZafateniMesta[Dva[0] / 8][Dva[0] % 8] && Ostanati[Dva[0]].t == DifFigures.tip.Pawn)) { // Валидирање за enpassant move Enpassant[1][Dva[0] % 8] = true; for (int i = 0; i < 8; i++) { if (Enpassant[1][i] && i != Dva[0] % 8) { Enpassant[1][i] = false; // Сите останати enpassant се false } } } // Рокада за црн лев топ && крал if (Castling[4] && Castling[5] && (Castling[6] || Castling[7])) { if (((kliknato2 == 0 && Dva[0] == 4) || (kliknato2 == 4 && Dva[0] == 0)) && Castling[6]) { Castling t = new Castling(matrica, false, true); if (t.ValidirajCastle()) { figures[Dva[0]].Image = null; figures[2].Image = Properties.Resources.Piece4; figures[2].SizeMode = PictureBoxSizeMode.StretchImage; figures[3].Image = Properties.Resources.Piece0; figures[3].SizeMode = PictureBoxSizeMode.StretchImage; figures[kliknato2].Image = null; for (int i = 5; i < 8; i++) { Castling[i] = false; } FinishedPlayer = false; PlayerTurn[3] = false; PlayerTurn[0] = true; this.SpecialDraw(); DifFigures pomosna = Ostanati[Dva[0]]; DifFigures pomosna2 = Ostanati[kliknato2]; Ostanati[3].t = DifFigures.tip.Rook; Ostanati[2].t = DifFigures.tip.King; Ostanati[0].t = DifFigures.tip.None; Ostanati[4].t = DifFigures.tip.None; matrica.ZafateniMesta[0][2] = true; matrica.ZafateniMesta[0][3] = true; matrica.ZafateniMesta[0][0] = false; matrica.ZafateniMesta[0][4] = false; matrica.Whitte[0][2] = false; matrica.Whitte[0][3] = false; Ostanati[2].White = false; Ostanati[3].White = false; label1.Text = "White's Turn"; } } // Рокада за крал и десен црн топ else if (((kliknato2 == 4 && Dva[0] == 7) || (kliknato2 == 7 && Dva[0] == 4)) && Castling[7]) { Castling t = new Castling(matrica, false, false); if (t.ValidirajCastle()) { figures[Dva[0]].Image = null; figures[5].Image = Properties.Resources.Piece0; figures[5].SizeMode = PictureBoxSizeMode.StretchImage; figures[6].Image = Properties.Resources.Piece4; figures[6].SizeMode = PictureBoxSizeMode.StretchImage; figures[kliknato2].Image = null; for (int i = 5; i < 8; i++) { Castling[i] = false; } FinishedPlayer = false; PlayerTurn[3] = false; PlayerTurn[0] = true; // Да ги отселектира валидните потези this.SpecialDraw(); DifFigures pomosna = Ostanati[Dva[0]]; DifFigures pomosna2 = Ostanati[kliknato2]; Ostanati[5].t = DifFigures.tip.Rook; Ostanati[6].t = DifFigures.tip.King; Ostanati[7].t = DifFigures.tip.None; Ostanati[4].t = DifFigures.tip.None; matrica.ZafateniMesta[0][5] = true; matrica.ZafateniMesta[0][6] = true; matrica.ZafateniMesta[0][4] = false; matrica.ZafateniMesta[0][7] = false; matrica.Whitte[0][5] = false; matrica.Whitte[0][6] = false; Ostanati[5].White = false; Ostanati[6].White = false; label1.Text = "White's Turn"; } } } // Проверка дали спротивниот крал е во Шах позиција if (k.figura.t == DifFigures.tip.King) { matrica.ZafateniMesta[Dva[0] / 8][Dva[0] % 8] = false; matrica.ZafateniMesta[kliknato2 / 8][kliknato2 % 8] = true; matrica.Whitte[kliknato2 / 8][kliknato2 % 8] = false; SahMat t = new SahMat(kliknato2, Ostanati, matrica, false); if (t.Value()) { k.Valid[kliknato2 / 8][kliknato2 % 8] = false; } matrica.ZafateniMesta[kliknato2 / 8][kliknato2 % 8] = false; } // Менување pictureboxes и зачувани фигури во array листата if (k.Valid[kliknato2 / 8][kliknato2 % 8]) { figures[kliknato2].Image = Pom1.Image; figures[kliknato2].SizeMode = PictureBoxSizeMode.StretchImage; figures[Dva[0]].Image = null; bool GoIma = false; int indGoIma = 0; TakenFigures pomosna = new TakenFigures(); // Додавање во листа, доколку е земена фигура if (Ostanati[kliknato2].t != DifFigures.tip.None) { TakenFigures l = new TakenFigures(); foreach (TakenFigures p in listBox2.Items) { pomosna = (TakenFigures)p; if (pomosna.v.Equals(Ostanati[kliknato2].t)) { GoIma = true; indGoIma = listBox2.Items.IndexOf(p); l = p; } } if (GoIma) { listBox2.Items.Remove(l); l.taken++; listBox2.Items.Add(l); } if (!GoIma) { WhiteTaken.Add(Ostanati[kliknato2].t); if (Ostanati[kliknato2].t == DifFigures.tip.Pawn) { listBox2.Items.Add(new TakenFigures(DifFigures.tip.Pawn, 1)); } else if (Ostanati[kliknato2].t == DifFigures.tip.Knight) { listBox2.Items.Add(new TakenFigures(DifFigures.tip.Knight, 1)); } else if (Ostanati[kliknato2].t == DifFigures.tip.Bishop) { listBox2.Items.Add(new TakenFigures(DifFigures.tip.Bishop, 1)); } else if (Ostanati[kliknato2].t == DifFigures.tip.Rook) { listBox2.Items.Add(new TakenFigures(DifFigures.tip.Rook, 1)); } else if (Ostanati[kliknato2].t == DifFigures.tip.Queen) { listBox2.Items.Add(new TakenFigures(DifFigures.tip.Queen, 1)); } else if (Ostanati[kliknato2].t == DifFigures.tip.King) { listBox2.Items.Add(new TakenFigures(DifFigures.tip.King, 1)); } } } // Ако сум го поместил кралот, или некој од топовите, оневозможување на рокада if (FinishedPlayer) { if (Dva[0] == 4) { Castling[5] = false; } if (Dva[0] == 0) { Castling[6] = false; } if (Dva[0] == 7) { Castling[7] = false; } bool enpa = false; // За enpassante дали е валиден if ((Dva[0] % 8 != kliknato2 % 8 && Dva[0] / 8 == 4 && kliknato2 / 8 == 5 && Ostanati[kliknato2].t == DifFigures.tip.None && Ostanati[Dva[0]].t == DifFigures.tip.Pawn && Ostanati[kliknato2 - 8].t == DifFigures.tip.Pawn)) { Ostanati[kliknato2 - 8].t = DifFigures.tip.None; Ostanati[kliknato2].t = DifFigures.tip.Pawn; Ostanati[Dva[0]].t = DifFigures.tip.None; if (ShowValid) { this.DrawIt(); } matrica.ZafateniMesta[kliknato2 / 8 - 1][kliknato2 % 8] = false; matrica.ZafateniMesta[kliknato2 / 8][kliknato2 % 8] = true; matrica.ZafateniMesta[Dva[0] / 8][Dva[0] % 8] = false; Ostanati[kliknato2].White = false; figures[kliknato2 - 8].Image = null; enpa = true; PlayerTurn[3] = false; PlayerTurn[0] = true; FinishedPlayer = false; bool goIma = false; TakenFigures t = new TakenFigures(); foreach (TakenFigures p in listBox2.Items) { if (p.v.Equals(DifFigures.tip.Pawn)) { goIma = true; t = p; } } if (goIma) { listBox2.Items.Remove(t); t.taken++; listBox2.Items.Add(t); } else { listBox2.Items.Add(new TakenFigures(DifFigures.tip.Pawn, 1)); } } // Ако enpa е true, тогаш е завршен потегот и не треба да влегува во овој иф if (!enpa) { Ostanati[kliknato2].t = Ostanati[Dva[0]].t; Ostanati[kliknato2].White = false; Ostanati[Dva[0]].White = false; Ostanati[Dva[0]].t = DifFigures.tip.None; PlayerTurn[3] = false; PlayerTurn[0] = true; FinishedPlayer = false; matrica.ZafateniMesta[kliknato2 / 8][kliknato2 % 8] = true; matrica.Whitte[kliknato2 / 8][kliknato2 % 8] = false; matrica.ZafateniMesta[Dva[0] / 8][Dva[0] % 8] = false; if (ShowValid) { this.DrawIt(); } } label1.Text = "White's Turn"; } bool Nekoja = false; // Го барам белиот крал за да проверам дали е во Шах позиција, доколку не го најдам, завршена е играта for (int i = 0; i < 64; i++) { if (Ostanati[i].t == DifFigures.tip.King && Ostanati[i].White) { indGoIma = i; Nekoja = true; } } if (Nekoja) { SahMat Krall = new SahMat(indGoIma, Ostanati, matrica, true); Krall.Val(); } else if (!Nekoja) { PlayerTurn[0] = PlayerTurn[1] = PlayerTurn[2] = PlayerTurn[3] = false; label1.Text = "Victory!!!"; File.AppendAllText("HighScores.txt", Environment.NewLine + vtorIgrac + " " + textBox2.Text + " " + prvIgrac + " " + textBox1.Text); MessageBox.Show("" + vtorIgrac + " победи! Честитки!", "Победа"); } // Доколку пионот стигне на другиот крај од шаховската табла if (kliknato2 / 8 == 7 && Ostanati[kliknato2].t == DifFigures.tip.Pawn) { MessageBox.Show("Pawn Promotion! Одберете друга фигура којашто сакате да ја замените наместо пионот"); PawnPromotion Promotion = new PawnPromotion(this, false, kliknato2, BlackTaken); Promotion.Show(); } } } if (PlayerTurn[2] && FinishedPlayer) { Keep = 0; k = new ValidMoves(Ostanati[kliknato], kliknato, matrica, Enpassant); Pom1.Image = figures[kliknato].Image; kliknato = Array.IndexOf(figures, ptt); if (Keep == 1) { Keep = 0; } Dva[Keep] = kliknato; Keep++; // Ако сум одбрал црна фигура и белите фигури завршиле if (!Ostanati[kliknato].t.Equals(DifFigures.tip.None) && PlayerTurn[2] && Ostanati[kliknato].White == false) { PictureBox pttt = (PictureBox)sender; Pom1.Image = pttt.Image; PlayerTurn[3] = true; PlayerTurn[2] = false; if (ShowValid) { DrawIt(); } } /* else if (!PlayerTurn[3] && (Ostanati[kliknato].t.Equals(DifFigures.tip.None) || Ostanati[kliknato].White)) * { * PlayerTurn[1] = false; * } */ } else if (PlayerTurn[1]) { kliknato2 = Array.IndexOf(figures, ptt); if (kliknato2 == -1) { kliknato2 = 0; PlayerTurn[1] = false; PlayerTurn[0] = true; } // Aко кликнам бело, селектирај ја новата фигура else if (k.Zafateni.Whitte[kliknato2 / 8][kliknato2 % 8] == true) { PlayerTurn[0] = true; } // Enpassante за бели фигури if ((kliknato2 / 8 == 4 && Dva[0] / 8 == 6 && matrica.ZafateniMesta[Dva[0] / 8][Dva[0] % 8] && Ostanati[Dva[0]].t == DifFigures.tip.Pawn)) { try { if (kliknato % 8 - 1 >= 0 && matrica.ZafateniMesta[4][kliknato2 % 8 - 1] && !matrica.Whitte[4][kliknato2 % 8 - 1] || (kliknato % 8 + 1 < 8) && matrica.ZafateniMesta[4][kliknato2 % 8 + 1] && !matrica.Whitte[4][kliknato2 % 8 + 1]) { Enpassant[0][Dva[0] % 8] = true; for (int i = 0; i < 8; i++) { if (Enpassant[0][i] && i != Dva[0] % 8) { Enpassant[0][i] = false; } } } } catch (Exception ent) { } } // Рокада за бел крал и десен бел топ if (Castling[0] && Castling[1] && (Castling[2] || Castling[3])) { if (((kliknato2 == 63 && Dva[0] == 60) || (kliknato2 == 60 && Dva[0] == 63)) && Castling[3]) { Castling t = new Castling(matrica, true, false); if (t.ValidirajCastle()) { this.SpecialDraw(); figures[Dva[0]].Image = null; figures[61].Image = Properties.Resources.Piece63; figures[61].SizeMode = PictureBoxSizeMode.StretchImage; figures[62].Image = Properties.Resources.Piece60; figures[62].SizeMode = PictureBoxSizeMode.StretchImage; figures[kliknato2].Image = null; for (int i = 0; i < 4; i++) { Castling[i] = false; } FinishedPlayer = true; PlayerTurn[1] = false; PlayerTurn[2] = true; DifFigures pomosna = Ostanati[Dva[0]]; DifFigures pomosna2 = Ostanati[kliknato2]; Ostanati[61].t = DifFigures.tip.Rook; Ostanati[62].t = DifFigures.tip.King; Ostanati[60].t = DifFigures.tip.None; Ostanati[63].t = DifFigures.tip.None; matrica.ZafateniMesta[7][5] = true; matrica.ZafateniMesta[7][6] = true; matrica.ZafateniMesta[7][7] = false; matrica.ZafateniMesta[7][4] = false; matrica.Whitte[7][5] = true; matrica.Whitte[7][6] = true; Ostanati[61].White = true; Ostanati[62].White = true; label1.Text = "Black's Turn"; } } // Рокада за лев бел топ и бел крал else if (((kliknato2 == 56 && Dva[0] == 60) || (kliknato2 == 60 && Dva[0] == 56)) && Castling[2]) { Castling t = new Castling(matrica, true, true); if (t.ValidirajCastle()) { this.SpecialDraw(); figures[Dva[0]].Image = null; figures[58].Image = Properties.Resources.Piece60; figures[58].SizeMode = PictureBoxSizeMode.StretchImage; figures[59].Image = Properties.Resources.Piece63; figures[59].SizeMode = PictureBoxSizeMode.StretchImage; figures[kliknato2].Image = null; for (int i = 0; i < 4; i++) { Castling[i] = false; } FinishedPlayer = true; PlayerTurn[1] = false; PlayerTurn[2] = true; DifFigures pomosna = Ostanati[Dva[0]]; DifFigures pomosna2 = Ostanati[kliknato2]; Ostanati[59].t = DifFigures.tip.Rook; Ostanati[58].t = DifFigures.tip.King; Ostanati[56].t = DifFigures.tip.None; Ostanati[60].t = DifFigures.tip.None; matrica.ZafateniMesta[7][2] = true; matrica.ZafateniMesta[7][3] = true; matrica.ZafateniMesta[7][0] = false; matrica.ZafateniMesta[7][4] = false; matrica.Whitte[7][2] = true; matrica.Whitte[7][3] = true; Ostanati[59].White = true; Ostanati[58].White = true; label1.Text = "Black's Turn"; } } } // Проверка дали кралот е уште во игра if (k.figura.t == DifFigures.tip.King) { matrica.ZafateniMesta[Dva[0] / 8][Dva[0] % 8] = false; matrica.ZafateniMesta[kliknato2 / 8][kliknato2 % 8] = true; matrica.Whitte[kliknato2 / 8][kliknato2 % 8] = true; SahMat t = new SahMat(kliknato2, Ostanati, matrica, true); if (t.Value()) { k.Valid[kliknato2 / 8][kliknato2 % 8] = false; } matrica.ZafateniMesta[kliknato2 / 8][kliknato2 % 8] = false; } if (k.Valid[kliknato2 / 8][kliknato2 % 8] && !FinishedPlayer) { figures[kliknato2].Image = Pom1.Image; figures[kliknato2].SizeMode = PictureBoxSizeMode.StretchImage; figures[Dva[0]].Image = null; TakenFigures pomosna = new TakenFigures(); bool GoIma = false; int indGoIma = 0; // Ако е земена фигура додај ја во листа if (Ostanati[kliknato2].t != DifFigures.tip.None) { TakenFigures l = new TakenFigures(); foreach (TakenFigures p in listBox1.Items) { pomosna = (TakenFigures)p; if (pomosna.v.Equals(Ostanati[kliknato2].t)) { GoIma = true; indGoIma = listBox1.Items.IndexOf(p); l = p; } } // Ако ја има фигурата зголеми го само бројот во листата if (GoIma) { listBox1.Items.Remove(l); pomosna.taken++; listBox1.Items.Add(l); } // Ако не, додај if (!GoIma) { BlackTaken.Add(Ostanati[kliknato2].t); if (Ostanati[kliknato2].t == DifFigures.tip.Pawn) { listBox1.Items.Add(new TakenFigures(DifFigures.tip.Pawn, 1)); } else if (Ostanati[kliknato2].t == DifFigures.tip.Knight) { listBox1.Items.Add(new TakenFigures(DifFigures.tip.Knight, 1)); } else if (Ostanati[kliknato2].t == DifFigures.tip.Bishop) { listBox1.Items.Add(new TakenFigures(DifFigures.tip.Bishop, 1)); } else if (Ostanati[kliknato2].t == DifFigures.tip.Rook) { listBox1.Items.Add(new TakenFigures(DifFigures.tip.Rook, 1)); } else if (Ostanati[kliknato2].t == DifFigures.tip.Queen) { listBox1.Items.Add(new TakenFigures(DifFigures.tip.Queen, 1)); } else if (Ostanati[kliknato2].t == DifFigures.tip.King) { listBox1.Items.Add(new TakenFigures(DifFigures.tip.King, 1)); } } } // Ако е поместен топ или крал, постави го соодветната булова за рокада false if (!FinishedPlayer) { if (Dva[0] == 60) { Castling[1] = false; } if (Dva[0] == 56) { Castling[2] = false; } if (Dva[0] == 63) { Castling[3] = false; } bool enpa = false; // Enpassante движење if ((Dva[0] % 8 != kliknato2 % 8 && Dva[0] / 8 == 3 && kliknato2 / 8 == 2 && Ostanati[kliknato2].t == DifFigures.tip.None && Ostanati[Dva[0]].t == DifFigures.tip.Pawn && Ostanati[kliknato2 + 8].t == DifFigures.tip.Pawn)) { Ostanati[kliknato2 + 8].t = DifFigures.tip.None; Ostanati[kliknato2].t = DifFigures.tip.Pawn; Ostanati[Dva[0]].t = DifFigures.tip.None; matrica.ZafateniMesta[kliknato2 / 8 + 1][kliknato2 % 8] = false; matrica.ZafateniMesta[kliknato2 / 8][kliknato2 % 8] = true; matrica.ZafateniMesta[Dva[0] / 8][Dva[0] % 8] = false; Ostanati[kliknato2].White = true; figures[kliknato2 + 8].Image = null; enpa = true; PlayerTurn[1] = false; PlayerTurn[2] = true; FinishedPlayer = true; if (ShowValid) { this.DrawIt(); } bool goIma = false; TakenFigures t = new TakenFigures(); foreach (TakenFigures p in listBox1.Items) { if (p.v.Equals(DifFigures.tip.Pawn)) { goIma = true; t = p; } } // Ако ја има, зголеми бројач if (goIma) { listBox1.Items.Remove(t); t.taken++; listBox1.Items.Add(t); } else { listBox1.Items.Add(new TakenFigures(DifFigures.tip.Pawn, 1)); } } // Ако не се случило enpassante движење (односно не е завршен играчот) if (!enpa & k.Valid[kliknato2 / 8][kliknato2 % 8]) { Ostanati[kliknato2].t = Ostanati[Dva[0]].t; Ostanati[kliknato2].White = true; Ostanati[Dva[0]].White = false; Ostanati[Dva[0]].t = DifFigures.tip.None; PlayerTurn[1] = false; PlayerTurn[2] = true; FinishedPlayer = true; matrica.ZafateniMesta[kliknato2 / 8][kliknato2 % 8] = true; matrica.Whitte[kliknato2 / 8][kliknato2 % 8] = true; matrica.ZafateniMesta[Dva[0] / 8][Dva[0] % 8] = false; matrica.Whitte[Dva[0] / 8][Dva[0] % 8] = false; if (ShowValid) { this.DrawIt(); } } bool Nekoja = false; // Барај го кралот for (int i = 0; i < 64; i++) { if (Ostanati[i].t == DifFigures.tip.King && !Ostanati[i].White) { indGoIma = i; Nekoja = true; } } // Провери дали е во шах label1.Text = "Black's Turn"; if (Nekoja) { SahMat Krall = new SahMat(indGoIma, Ostanati, matrica, false); Krall.Val(); } // Кралот е погубен else if (!Nekoja) { PlayerTurn[0] = PlayerTurn[1] = PlayerTurn[2] = PlayerTurn[3] = false; label1.Text = "Victory!!!"; MessageBox.Show("" + prvIgrac + " победи! Честитки!", "Победа"); File.AppendAllText("HighScores.txt", Environment.NewLine + prvIgrac + " " + textBox1.Text + " " + vtorIgrac + " " + textBox2.Text); } // Пиончето стигнало на крајот од шаховската табла if (kliknato2 / 8 == 0 && Ostanati[kliknato2].t == DifFigures.tip.Pawn) { MessageBox.Show("Pawn Promotion! Одберете друга фигура којашто сакате да ја замените наместо пионот"); PawnPromotion Promotion = new PawnPromotion(this, true, kliknato2, WhiteTaken); Promotion.Show(); } } } } if (PlayerTurn[0]) { k = new ValidMoves(Ostanati[kliknato], kliknato, matrica, Enpassant); Pom1.SizeMode = PictureBoxSizeMode.StretchImage; Pom1.Image = figures[kliknato].Image; kliknato = Array.IndexOf(figures, ptt); if (Keep >= 1) { Keep = 0; } Dva[Keep] = kliknato; Keep++; if (Keep == 1) { Keep = 0; } if (kliknato == -1) { kliknato = 0; PlayerTurn[2] = false; PlayerTurn[0] = true; } else if (!Ostanati[kliknato].t.Equals(DifFigures.tip.None) && PlayerTurn[0] && Ostanati[kliknato].White == true) { if (ShowValid) { this.DrawIt(); } PictureBox pttt = (PictureBox)sender; Pom1.Image = pttt.Image; PlayerTurn[1] = true; PlayerTurn[0] = false; } // Ако е кликнато нешто што не е бела фигура else if (!PlayerTurn[1] && (Ostanati[kliknato].t.Equals(DifFigures.tip.None) || !Ostanati[kliknato].White)) { PlayerTurn[1] = false; } } }
public void generatePotezi(DifFigures.tip t, int index, bool White, TakenPlaces Zafateni, bool[][] Enpassant) { if (t.Equals(DifFigures.tip.Pawn) && !White) { // Поле напред if ((index / 8) + 1 < 8) { if (!(Zafateni.ZafateniMesta[index / 8 + 1][index % 8])) { Valid[(index / 8) + 1][(index % 8)] = true; } } // Поле лево напред, доколку е зафатено if (index / 8 + 1 < 8 && ((index % 8) - 1) >= 0) { if (Zafateni.ZafateniMesta[index / 8 + 1][index % 8 - 1] && Zafateni.Whitte[index / 8 + 1][index % 8 - 1] == true) { Valid[(index / 8) + 1][(index % 8) - 1] = true; } } // Поле десно напред, доколку е зафатено if ((index / 8) + 1 < 8 && ((index % 8) + 1) < 8) { if (Zafateni.ZafateniMesta[index / 8 + 1][index % 8 + 1] && Zafateni.Whitte[index / 8 + 1][index % 8 + 1] == true) { Valid[(index / 8) + 1][(index % 8) + 1] = true; } } // Поле две напред, доколку на почетна позиција && поле едно напред не е зафатено if (index / 8 == 1 && index / 8 + 2 < 8) { if (!Zafateni.ZafateniMesta[index / 8 + 2][index % 8] && !Zafateni.ZafateniMesta[index / 8 + 1][index % 8]) { Valid[(index / 8) + 2][index % 8] = true; } } // Enpassantе валидност десно if (index % 8 + 1 < 8) { if (index % 8 + 1 < 8 && index / 8 == 4 && Enpassant[0][index % 8 + 1]) { Valid[5][index % 8 + 1] = true; IsEnpassant = true; } } // Enpassante лево if (index % 8 - 1 >= 0) { if (index % 8 - 1 >= 0 && index / 8 == 4 && Enpassant[0][index % 8 - 1]) { Valid[5][index % 8 - 1] = true; IsEnpassant = true; } } } // Исто за бел пион else if (t.Equals(DifFigures.tip.Pawn) && White) { if ((index / 8) - 1 >= 0) { if (!Zafateni.ZafateniMesta[index / 8 - 1][index % 8] && Zafateni.Whitte[index / 8 - 1][index % 8] == false) { Valid[(index / 8) - 1][(index % 8)] = true; } } if (index / 8 - 1 >= 0 && ((index % 8) - 1) >= 0) { if (Zafateni.ZafateniMesta[index / 8 - 1][index % 8 - 1] && Zafateni.Whitte[index / 8 - 1][index % 8 - 1] == false) { Valid[(index / 8) - 1][(index % 8) - 1] = true; } } if ((index / 8) - 1 >= 0 && ((index % 8) + 1) < 8) { if (Zafateni.ZafateniMesta[index / 8 - 1][index % 8 + 1] && Zafateni.Whitte[index / 8 - 1][index % 8 + 1] == false) { Valid[(index / 8) - 1][(index % 8) + 1] = true; } } if (index / 8 == 6 && index / 8 - 2 >= 0) { if (!Zafateni.ZafateniMesta[index / 8 - 2][index % 8] && !Zafateni.ZafateniMesta[index / 8 - 1][index % 8]) { Valid[(index / 8) - 2][index % 8] = true; } } if (index % 8 + 1 < 8) { if (index % 8 + 1 < 8 && index / 8 == 3 && Enpassant[1][index % 8 + 1]) { Valid[2][index % 8 + 1] = true; IsEnpassant = true; } } if (index % 8 - 1 >= 0) { if (index % 8 - 1 >= 0 && index / 8 == 3 && Enpassant[1][index % 8 - 1]) { Valid[2][index % 8 - 1] = true; IsEnpassant = true; } } } // Валидни потези за кралот (Напред (лево, право, десно), лево, десно, Назад (лево, право, десно)) else if (t.Equals(DifFigures.tip.King)) { if (White) { if (index / 8 + 1 < 8 && index % 8 + 1 < 8) { if (!Zafateni.Whitte[(index / 8) + 1][(index % 8) + 1] || !Zafateni.ZafateniMesta[(index / 8) + 1][(index % 8) + 1]) { Valid[(index / 8) + 1][(index % 8) + 1] = true; } } if (index / 8 + 1 < 8 && index % 8 - 1 >= 0) { if (!Zafateni.Whitte[(index / 8) + 1][(index % 8) - 1] || !Zafateni.ZafateniMesta[(index / 8) + 1][(index % 8) - 1]) { Valid[(index / 8) + 1][(index % 8) - 1] = true; } } if ((index / 8 - 1 >= 0 && index % 8 + 1 < 8)) { if (!Zafateni.Whitte[(index / 8) - 1][(index % 8) + 1] || !Zafateni.ZafateniMesta[(index / 8) - 1][(index % 8) + 1]) { Valid[(index / 8) - 1][(index % 8) + 1] = true; } } if ((index / 8 - 1 >= 0 && index % 8 - 1 >= 0)) { if (!Zafateni.Whitte[(index / 8) - 1][(index % 8) - 1] || !Zafateni.ZafateniMesta[(index / 8) - 1][(index % 8) - 1]) { Valid[(index / 8) - 1][(index % 8) - 1] = true; } } if (index % 8 + 1 < 8) { if (!Zafateni.Whitte[(index / 8)][(index % 8) + 1] || !Zafateni.ZafateniMesta[(index / 8)][(index % 8) + 1]) { Valid[(index / 8)][(index % 8) + 1] = true; } } if (index % 8 - 1 >= 0) { if (!Zafateni.Whitte[(index / 8)][(index % 8) - 1] || !Zafateni.ZafateniMesta[(index / 8)][(index % 8) - 1]) { Valid[(index / 8)][(index % 8) - 1] = true; } } if (index / 8 + 1 < 8) { if (!Zafateni.Whitte[(index / 8 + 1)][(index % 8)] || !Zafateni.ZafateniMesta[(index / 8 + 1)][(index % 8)]) { Valid[(index / 8) + 1][(index % 8)] = true; } } if (index / 8 - 1 >= 0) { if (!Zafateni.Whitte[(index / 8 - 1)][(index % 8)] || !Zafateni.ZafateniMesta[(index / 8 - 1)][(index % 8)]) { Valid[(index / 8) - 1][(index % 8)] = true; } } } else if (!White) { if (index / 8 + 1 < 8 && index % 8 + 1 < 8) { if (Zafateni.Whitte[(index / 8) + 1][(index % 8) + 1] || !Zafateni.ZafateniMesta[(index / 8) + 1][(index % 8) + 1]) { Valid[(index / 8) + 1][(index % 8) + 1] = true; } } if (index / 8 + 1 < 8 && index % 8 - 1 >= 0) { if (Zafateni.Whitte[(index / 8) + 1][(index % 8) - 1] || !Zafateni.ZafateniMesta[(index / 8) + 1][(index % 8) - 1]) { Valid[(index / 8) + 1][(index % 8) - 1] = true; } } if ((index / 8 - 1 >= 0 && index % 8 + 1 < 8)) { if (Zafateni.Whitte[(index / 8) - 1][(index % 8) + 1] || !Zafateni.ZafateniMesta[(index / 8) - 1][(index % 8) + 1]) { Valid[(index / 8) - 1][(index % 8) + 1] = true; } } if ((index / 8 - 1 >= 0 && index % 8 - 1 >= 0)) { if (Zafateni.Whitte[(index / 8) - 1][(index % 8) - 1] || !Zafateni.ZafateniMesta[(index / 8) - 1][(index % 8) - 1]) { Valid[(index / 8) - 1][(index % 8) - 1] = true; } } if (index % 8 + 1 < 8) { if (Zafateni.Whitte[(index / 8)][(index % 8) + 1] || !Zafateni.ZafateniMesta[(index / 8)][(index % 8) + 1]) { Valid[(index / 8)][(index % 8) + 1] = true; } } if (index % 8 - 1 >= 0) { if (Zafateni.Whitte[(index / 8)][(index % 8) - 1] || !Zafateni.ZafateniMesta[(index / 8)][(index % 8) - 1]) { Valid[(index / 8)][(index % 8) - 1] = true; } } if (index / 8 + 1 < 8) { if (Zafateni.Whitte[(index / 8 + 1)][(index % 8)] || !Zafateni.ZafateniMesta[(index / 8 + 1)][(index % 8)]) { Valid[(index / 8) + 1][(index % 8)] = true; } } if (index / 8 - 1 >= 0) { if (Zafateni.Whitte[(index / 8 - 1)][(index % 8)] || !Zafateni.ZafateniMesta[(index / 8 - 1)][(index % 8)]) { Valid[(index / 8) - 1][(index % 8)] = true; } } } } else if (t.Equals(DifFigures.tip.Rook)) { int[] Tocki = new int[4]; Tocki[0] = -1; Tocki[1] = -1; Tocki[2] = -1; Tocki[3] = -1; int min = Int16.MinValue; for (int i = index / 8 - 1; i >= 0; i--) { if (Zafateni.ZafateniMesta[i][index % 8]) { if (min < i) { Tocki[0] = i; min = i; } } } min = Int32.MaxValue; for (int i = index / 8 + 1; i < 8; i++) { if (Zafateni.ZafateniMesta[i][index % 8]) { if (min > i) { min = i; Tocki[1] = i; } } } min = Int32.MinValue; for (int j = index % 8 - 1; j >= 0; j--) { if (Zafateni.ZafateniMesta[index / 8][j]) { if (min < j) { Tocki[2] = j; min = j; } break; } } min = Int32.MaxValue; for (int j = index % 8 + 1; j < 8; j++) { if (Zafateni.ZafateniMesta[index / 8][j]) { if (min > j) { min = j; Tocki[3] = j; } } } if (Tocki[0] == -1) { Tocki[0] = 0; } if (Tocki[1] == -1) { Tocki[1] = 7; } if (Tocki[2] == -1) { Tocki[2] = 0; } if (Tocki[3] == -1) { Tocki[3] = 7; } if (White) { for (int i = Tocki[0]; i <= Tocki[1]; i++) { if (!Zafateni.Whitte[i][index % 8] || !Zafateni.ZafateniMesta[i][index % 8]) { Valid[i][index % 8] = true; } } for (int j = Tocki[2]; j <= Tocki[3]; j++) { if (!Zafateni.Whitte[index / 8][j] || !Zafateni.ZafateniMesta[index / 8][j]) { Valid[index / 8][j] = true; } } } else if (!White) { for (int i = Tocki[0]; i <= Tocki[1]; i++) { if (Zafateni.Whitte[i][index % 8] || !Zafateni.ZafateniMesta[i][index % 8]) { Valid[i][index % 8] = true; } } for (int j = Tocki[2]; j <= Tocki[3]; j++) { if (Zafateni.Whitte[index / 8][j] || !Zafateni.ZafateniMesta[index / 8][j]) { Valid[index / 8][j] = true; } } } Valid[index / 8][index % 8] = false; } else if (t.Equals(DifFigures.tip.Knight)) { if (White) { try { if (!Zafateni.Whitte[(index / 8) - 2][(index % 8) - 1] || !Zafateni.ZafateniMesta[(index / 8) - 2][(index % 8) - 1]) { Valid[(index / 8) - 2][(index % 8) - 1] = true; } } catch (Exception e) { } try { if (!Zafateni.Whitte[(index / 8) - 2][(index % 8) + 1] || !Zafateni.ZafateniMesta[(index / 8) - 2][(index % 8) + 1]) { Valid[(index / 8) - 2][(index % 8) + 1] = true; } } catch (Exception e) { } try { if (!Zafateni.Whitte[(index / 8) - 1][(index % 8) + 2] || !Zafateni.ZafateniMesta[(index / 8) - 1][(index % 8) + 2]) { Valid[(index / 8) - 1][(index % 8) + 2] = true; } } catch (Exception e) { } try { if (!Zafateni.Whitte[(index / 8) - 1][(index % 8) - 2] || !Zafateni.ZafateniMesta[(index / 8) - 1][(index % 8) - 2]) { Valid[(index / 8) - 1][(index % 8) - 2] = true; } } catch (Exception e) { } try { if (!Zafateni.Whitte[(index / 8) + 2][(index % 8) - 1] || !Zafateni.ZafateniMesta[(index / 8) + 2][(index % 8) - 1]) { Valid[(index / 8) + 2][(index % 8) - 1] = true; } } catch (Exception e) { } try { if (!Zafateni.Whitte[(index / 8) + 2][(index % 8) + 1] || !Zafateni.ZafateniMesta[(index / 8) + 2][(index % 8) + 1]) { Valid[(index / 8) + 2][(index % 8) + 1] = true; } } catch (Exception e) { } try { if (!Zafateni.Whitte[(index / 8) + 1][(index % 8) - 2] || !Zafateni.ZafateniMesta[(index / 8) + 1][(index % 8) - 2]) { Valid[(index / 8) + 1][(index % 8) - 2] = true; } } catch (Exception e) { } try { if (!Zafateni.Whitte[(index / 8) + 1][(index % 8) + 2] || !Zafateni.ZafateniMesta[(index / 8) + 1][(index % 8) + 2]) { Valid[(index / 8) + 1][(index % 8) + 2] = true; } } catch (Exception e) { } } else if (!White) { try { if (Zafateni.Whitte[(index / 8) - 2][(index % 8) - 1] || !Zafateni.ZafateniMesta[(index / 8) - 2][(index % 8) - 1]) { Valid[(index / 8) - 2][(index % 8) - 1] = true; } } catch (Exception e) { } try { if (Zafateni.Whitte[(index / 8) - 2][(index % 8) + 1] || !Zafateni.ZafateniMesta[(index / 8) - 2][(index % 8) + 1]) { Valid[(index / 8) - 2][(index % 8) + 1] = true; } } catch (Exception e) { } try { if (Zafateni.Whitte[(index / 8) - 1][(index % 8) + 2] || !Zafateni.ZafateniMesta[(index / 8) - 1][(index % 8) + 2]) { Valid[(index / 8) - 1][(index % 8) + 2] = true; } } catch (Exception e) { } try { if (Zafateni.Whitte[(index / 8) - 1][(index % 8) - 2] || !Zafateni.ZafateniMesta[(index / 8) - 1][(index % 8) - 2]) { Valid[(index / 8) - 1][(index % 8) - 2] = true; } } catch (Exception e) { } try { if (Zafateni.Whitte[(index / 8) + 2][(index % 8) - 1] || !Zafateni.ZafateniMesta[(index / 8) + 2][(index % 8) - 1]) { Valid[(index / 8) + 2][(index % 8) - 1] = true; } } catch (Exception e) { } try { if (Zafateni.Whitte[(index / 8) + 2][(index % 8) + 1] || !Zafateni.ZafateniMesta[(index / 8) + 2][(index % 8) + 1]) { Valid[(index / 8) + 2][(index % 8) + 1] = true; } } catch (Exception e) { } try { if (Zafateni.Whitte[(index / 8) + 1][(index % 8) - 2] || !Zafateni.ZafateniMesta[(index / 8) + 1][(index % 8) - 2]) { Valid[(index / 8) + 1][(index % 8) - 2] = true; } } catch (Exception e) { } try { if (Zafateni.Whitte[(index / 8) + 1][(index % 8) + 2] || !Zafateni.ZafateniMesta[(index / 8) + 1][(index % 8) + 2]) { Valid[(index / 8) + 1][(index % 8) + 2] = true; } } catch (Exception e) { } } } else if (t.Equals(DifFigures.tip.Bishop)) { int[][] Tocki = new int[4][]; for (int i = 0; i < 4; i++) { Tocki[i] = new int[2]; } for (int i = 0; i < 4; i++) { for (int j = 0; j < 2; j++) { Tocki[i][j] = -1; } } int min = Int16.MinValue; bool barEdno = (index / 8 - 1 >= 0 && index % 8 - 1 >= 0); for (int a = index / 8 - 1, nesto = index % 8 - 1; a >= 0 && nesto >= 0; a--, nesto--) { if (Zafateni.ZafateniMesta[a][nesto]) { if (min < a) { Tocki[0][0] = a; Tocki[0][1] = nesto; min = a; } barEdno = false; } else if (barEdno) { Tocki[0][0] = a; Tocki[0][1] = nesto; } } barEdno = (index / 8 + 1 < 8 && index % 8 + 1 < 8); min = Int32.MaxValue; for (int a = index / 8 + 1, nesto = index % 8 + 1; a < 8 && nesto < 8; a++, nesto++) { if (Zafateni.ZafateniMesta[a][nesto]) { if (min > a) { Tocki[1][0] = a; Tocki[1][1] = nesto; min = a; } barEdno = false; } else if (barEdno) { Tocki[1][0] = a; Tocki[1][1] = nesto; } } barEdno = (index / 8 + 1 < 8 && index % 8 - 1 >= 0); min = Int32.MaxValue; for (int a = index / 8 + 1, nesto = index % 8 - 1; a < 8 && nesto >= 0; a++, nesto--) { if (Zafateni.ZafateniMesta[a][nesto]) { if (min > a) { Tocki[2][0] = a; Tocki[2][1] = nesto; min = a; } barEdno = false; } else if (barEdno) { Tocki[2][0] = a; Tocki[2][1] = nesto; } } min = Int32.MinValue; barEdno = (index / 8 - 1 >= 0 && index % 8 + 1 < 8); for (int a = index / 8 - 1, nesto = index % 8 + 1; a >= 0 && nesto < 8; a--, nesto++) { if (Zafateni.ZafateniMesta[a][nesto]) { if (min < a) { Tocki[3][0] = a; Tocki[3][1] = nesto; min = a; } barEdno = false; } else if (barEdno) { Tocki[3][0] = a; Tocki[3][1] = nesto; } } if (Tocki[0][0] == -1) { Tocki[0][0] = index / 8; Tocki[0][1] = index % 8; } if (Tocki[1][0] == -1) { Tocki[1][0] = index / 8; Tocki[1][1] = index % 8; } if (Tocki[2][0] == -1) { Tocki[2][0] = index / 8; Tocki[2][1] = index % 8; } if (Tocki[3][0] == -1) { Tocki[3][0] = index / 8; Tocki[3][1] = index % 8; } if (White) { for (int i = Tocki[0][0], j = Tocki[0][1]; i <= Tocki[1][0] && j <= Tocki[1][1]; i++, j++) { if (!Zafateni.Whitte[i][j] || !Zafateni.ZafateniMesta[i][j]) { Valid[i][j] = true; } } for (int i = Tocki[2][0], j = Tocki[2][1]; i >= Tocki[3][0] && j <= Tocki[3][1]; i--, j++) { if (!Zafateni.Whitte[i][j] || !Zafateni.ZafateniMesta[i][j]) { Valid[i][j] = true; } } } if (!(White)) { for (int i = Tocki[0][0], j = Tocki[0][1]; i <= Tocki[1][0] && j <= Tocki[1][1]; i++, j++) { if (Zafateni.Whitte[i][j] || !Zafateni.ZafateniMesta[i][j]) { Valid[i][j] = true; } } for (int i = Tocki[2][0], j = Tocki[2][1]; i >= Tocki[3][0] && j <= Tocki[3][1]; i--, j++) { if (Zafateni.Whitte[i][j] || !Zafateni.ZafateniMesta[i][j]) { Valid[i][j] = true; } } } Valid[index / 8][index % 8] = false; } else if (t.Equals(DifFigures.tip.Queen)) { DifFigures Top = new DifFigures(); Top.t = DifFigures.tip.Rook; Top.White = this.figura.White; ValidMoves pom1 = new ValidMoves(Top, this.index, this.Zafateni, Enpassant); DifFigures Lamfer = new DifFigures(); Lamfer.t = DifFigures.tip.Bishop; Lamfer.White = this.figura.White; ValidMoves pom2 = new ValidMoves(Lamfer, this.index, this.Zafateni, Enpassant); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { Valid[i][j] = (pom1.Valid[i][j] || pom2.Valid[i][j]); } } Valid[index / 8][index % 8] = false; } }