private void button3_Click(object sender, EventArgs e) { button3.Enabled = false; string r, g, b = ""; Bitmap bMap = pictureBox2.Image as Bitmap; //Bitmap bMap = Bitmap.FromFile(@"C:/Users/Thayná/Desktop/Ju/DBO Bot/imagens/img"+ Convert.ToString(i) +".png") as Bitmap; if (bMap == null) { throw new FileNotFoundException("Cannot open picture file for analysis"); } cor p = new cor(); p.GetMostUsedColor(bMap); lblcor.Text = p.MostUsedColor.ToString(); r = p.MostUsedColor.R.ToString(); lblR.Text = "R " + p.MostUsedColor.R.ToString(); g = p.MostUsedColor.G.ToString(); lblG.Text = "G " + p.MostUsedColor.G.ToString(); b = p.MostUsedColor.B.ToString(); lblB.Text = "B " + p.MostUsedColor.B.ToString(); if ((Convert.ToInt32(r) >= 45) && (Convert.ToInt32(r) <= 50) && (Convert.ToInt32(g) >= 94) && (Convert.ToInt32(g) <= 100) && (Convert.ToInt32(b) >= 150) && (Convert.ToInt32(b) <= 155)) { } button3.Enabled = true; }
public peça(posicao posicao, tabuleiro tab, cor cor) { this.posicao = posicao; this.tab = tab; this.cor = cor; this.qteMovimentos = 0; }
public peca(Tabuleiro tab, cor cor) { this.posicao = null; this.tab = tab; this.cor = cor; this.qteMovimentos = 0; }
public bool testeXequemate(cor cor) { if (!estaEmXeque(cor)) { return(false); } foreach (peca x in pecasEmJogo(cor)) { bool[,] mat = x.movimentosPossiveis(); for (int i = 0; i < tab.linhas; i++) { for (int j = 0; j < tab.colunas; j++) { if (mat[i, j]) { Posicao origem = x.posicao; Posicao destino = new Posicao(i, j); peca pecaCapturada = executaMovimento(origem, destino); bool testeXeque = estaEmXeque(cor); desfazMovimento(origem, destino, pecaCapturada); if (!testeXeque) { return(false); } } } } } return(true); }
private peca rei(cor cor) { foreach (peca x in pecasEmJogo(cor)) { if (x is rei) { return(x); } } return(null); }
private cor adversaria(cor cor) { if (cor == cor.Branca) { return(cor.Preta); } else { return(cor.Branca); } }
public HashSet <peca> pecasCapturadas(cor cor) { HashSet <peca> aux = new HashSet <peca>(); foreach (peca x in capturadas) { if (x.cor == cor) { aux.Add(x); } } return(aux); }
public HashSet <peca> pecasEmJogo(cor cor) { HashSet <peca> aux = new HashSet <peca>(); foreach (peca x in pecas) { if (x.cor == cor) { aux.Add(x); } } aux.ExceptWith(pecasCapturadas(cor)); return(aux); }
public bool estaEmXeque(cor cor) { peca R = rei(cor); if (R == null) { throw new tabuleiroException("Não tem rei da cor" + cor + "no tabuleiro!"); } foreach (peca x in pecasEmJogo(adversaria(cor))) { bool[,] mat = x.movimentosPossiveis(); if (mat[R.posicao.linha, R.posicao.coluna]) { return(true); } } return(false); }
public peao(Tabuleiro tab, cor cor, PartidaDeXadrez partida) : base(tab, cor) { this.partida = partida; }
public dama(Tabuleiro tab, cor cor) : base(tab, cor) { }
public void verde() { semafaro.Image = testes.Properties.Resources.sinal_verde; sinal = cor.Verde; }
public void amerelo() { semafaro.Image = testes.Properties.Resources.sinal_amarelo; sinal = cor.Amarelo; }
public torre(Tabuleiro tab, cor cor) : base(tab, cor) { }
public String OControl(moveC move, properties piece, Int32? stepSize, String Direction) { String removeID = "";//silinecek taşın id si Boolean isMoveable = false;//taş hareket edebilirmi List<cor> se = new List<cor>(); List<properties> ps = new List<properties>(); var item = new cor(); int x = piece.row; int y = piece.col; switch (Direction) { case "direct": { if (piece.row != move.row && piece.col != move.col) break; if (stepSize == null)//adım sayısı null ise sınır yoktur { stepSize = Math.Abs(move.col - piece.col) != 0 ? Math.Abs(move.col - piece.col) : Math.Abs(move.row - piece.row); } else { if (Math.Abs(piece.row - move.row) == stepSize || Math.Abs(piece.row - move.row) == 1)//adım sayısı belirtilir { stepSize = Math.Abs(piece.row - move.row); } else if (Math.Abs(piece.col - move.col) == stepSize || Math.Abs(piece.col - move.col) == 1) { stepSize = Math.Abs(piece.col - move.col); } else { break; } } for (int i = 1; i <= stepSize; i++)//hareket ettiği ekseni bul { if (move.row >= piece.row && x + i <= 8 && piece.col == move.col)//x+ { se.Add(new cor() { col = y, row = x + i }); } if (move.row < piece.row && x - i >= 1 && piece.col == move.col)//x- { se.Add(new cor() { col = y, row = x - i }); } if (move.col >= piece.col && y + i <= 8 && piece.row == move.row)//y+ { se.Add(new cor() { col = y + i, row = x }); } if (move.col <= piece.col && y - i >= 1 && piece.row == move.row)//y- { se.Add(new cor() { col = y - i, row = x }); } } break; } case "cross": { if (piece.row == move.row || piece.col == move.col) break; if (stepSize == null) { stepSize = Math.Abs(move.col - piece.col); } else { if (Math.Abs(piece.row - move.row) != 1 || Math.Abs(piece.col - move.col) != 1) { break; } } for (int i = 1; i <= stepSize; i++) { if (move.row > piece.row && move.col > piece.col && x + i <= 8 && y + i <= 8)//x+ y+ { se.Add(new cor() { col = y + i, row = x + i }); } if (move.row < piece.row && move.col < piece.col && x - i >= 1 && y - i >= 1)//x- y- { se.Add(new cor() { col = y - i, row = x - i }); } if (move.row > piece.row && move.col < piece.col && x + i <= 8 && y - i >= 1)//x+ y- { se.Add(new cor() { col = y - i, row = x + i }); } if (move.row < piece.row && move.col > piece.col && x - i >= 1 && y + i <= 8)//x- y+ { se.Add(new cor() { col = y + i, row = x - i }); } } break; } case "L": { if (move.col == y + 1 && move.row == x + 2 && x + 2 <= 8 && y + 1 <= 8)//y+1 x+2 { se.Add(new cor() { col = y + 1, row = x + 2 }); } if (move.col == y + 1 && move.row == x - 2 && x - 2 >= 1 && y + 1 <= 8)//y+1 x-2 { se.Add(new cor() { col = y + 1, row = x - 2 }); } if (move.col == y + 2 && move.row == x + 1 && x + 1 <= 8 && y + 2 <= 8)//y+2 x+1 { se.Add(new cor() { col = y + 2, row = x + 1 }); } if (move.col == y + 2 && move.row == x - 1 && x - 1 >= 1 && y + 2 <= 8)//y+2 x-1 { se.Add(new cor() { col = y + 2, row = x - 1 }); } if (move.col == y - 1 && move.row == x + 2 && x + 2 <= 8 && y - 1 >= 1)//y-1 x+2 { se.Add(new cor() { col = y - 1, row = x + 2 }); } if (move.col == y - 1 && move.row == x - 2 && x - 2 >= 1 && y - 1 >= 1)//y-1 x-2 { se.Add(new cor() { col = y - 1, row = x - 2 }); } if (move.col == y - 2 && move.row == x + 1 && x + 1 <= 8 && y - 2 <= 8)//y-2 x+1 { se.Add(new cor() { col = y - 2, row = x + 1 }); } if (move.col == y - 2 && move.row == x - 1 && x - 1 >= 1 && y - 2 <= 8)//y-2 x-1 { se.Add(new cor() { col = y - 2, row = x - 1 }); } break; } default: break; } foreach (var direct in se)//hareket ettiği eksende hangi taşlar var { foreach (var pc in listPieces.pieces) { if (direct.row == pc.row && direct.col == pc.col) { ps.Add(pc); } } } if (se.Count > 0) { if (ps.Count == 0)//önünde taş yoksa hareket edebilir { if (Direction == "cross" && piece.name == piece.getName.pawn) { } else { isMoveable = true; } } if (ps.Count == 1 && ps[0].color != piece.color)//önünde karşı takımın taşı varsa yenebilirmi { if (Direction == "direct" && piece.name == piece.getName.pawn) { } else { listPieces.pieces.RemoveAll(a => a.id == ps[0].id);//listeden yenen elemanı çıkartıyoruz removeID = ps[0].id;//client tarafta silinecek olan taşın id sini gönderiyoruz isMoveable = true; } } if (isMoveable == true)//hareket kabul edildiyse { piece.col = move.col;//kalenin yeni sutun değerini güncelle piece.row = move.row;//kalenin yeni satır değeri güncelle piece.isStart = true;// ilk hareket aktif et } } return isMoveable + ";" + removeID; }
public String OControl(moveC move, properties piece, Int32?stepSize, String Direction) { String removeID = ""; //silinecek taşın id si Boolean isMoveable = false; //taş hareket edebilirmi List <cor> se = new List <cor>(); List <properties> ps = new List <properties>(); var item = new cor(); int x = piece.row; int y = piece.col; switch (Direction) { case "direct": { if (piece.row != move.row && piece.col != move.col) { break; } if (stepSize == null) //adım sayısı null ise sınır yoktur { stepSize = Math.Abs(move.col - piece.col) != 0 ? Math.Abs(move.col - piece.col) : Math.Abs(move.row - piece.row); } else { if (Math.Abs(piece.row - move.row) == stepSize || Math.Abs(piece.row - move.row) == 1) //adım sayısı belirtilir { stepSize = Math.Abs(piece.row - move.row); } else if (Math.Abs(piece.col - move.col) == stepSize || Math.Abs(piece.col - move.col) == 1) { stepSize = Math.Abs(piece.col - move.col); } else { break; } } for (int i = 1; i <= stepSize; i++) //hareket ettiği ekseni bul { if (move.row >= piece.row && x + i <= 8 && piece.col == move.col) //x+ { se.Add(new cor() { col = y, row = x + i }); } if (move.row < piece.row && x - i >= 1 && piece.col == move.col) //x- { se.Add(new cor() { col = y, row = x - i }); } if (move.col >= piece.col && y + i <= 8 && piece.row == move.row) //y+ { se.Add(new cor() { col = y + i, row = x }); } if (move.col <= piece.col && y - i >= 1 && piece.row == move.row) //y- { se.Add(new cor() { col = y - i, row = x }); } } break; } case "cross": { if (piece.row == move.row || piece.col == move.col) { break; } if (stepSize == null) { stepSize = Math.Abs(move.col - piece.col); } else { if (Math.Abs(piece.row - move.row) != 1 || Math.Abs(piece.col - move.col) != 1) { break; } } for (int i = 1; i <= stepSize; i++) { if (move.row > piece.row && move.col > piece.col && x + i <= 8 && y + i <= 8) //x+ y+ { se.Add(new cor() { col = y + i, row = x + i }); } if (move.row < piece.row && move.col < piece.col && x - i >= 1 && y - i >= 1) //x- y- { se.Add(new cor() { col = y - i, row = x - i }); } if (move.row > piece.row && move.col < piece.col && x + i <= 8 && y - i >= 1) //x+ y- { se.Add(new cor() { col = y - i, row = x + i }); } if (move.row < piece.row && move.col > piece.col && x - i >= 1 && y + i <= 8) //x- y+ { se.Add(new cor() { col = y + i, row = x - i }); } } break; } case "L": { if (move.col == y + 1 && move.row == x + 2 && x + 2 <= 8 && y + 1 <= 8) //y+1 x+2 { se.Add(new cor() { col = y + 1, row = x + 2 }); } if (move.col == y + 1 && move.row == x - 2 && x - 2 >= 1 && y + 1 <= 8) //y+1 x-2 { se.Add(new cor() { col = y + 1, row = x - 2 }); } if (move.col == y + 2 && move.row == x + 1 && x + 1 <= 8 && y + 2 <= 8) //y+2 x+1 { se.Add(new cor() { col = y + 2, row = x + 1 }); } if (move.col == y + 2 && move.row == x - 1 && x - 1 >= 1 && y + 2 <= 8) //y+2 x-1 { se.Add(new cor() { col = y + 2, row = x - 1 }); } if (move.col == y - 1 && move.row == x + 2 && x + 2 <= 8 && y - 1 >= 1) //y-1 x+2 { se.Add(new cor() { col = y - 1, row = x + 2 }); } if (move.col == y - 1 && move.row == x - 2 && x - 2 >= 1 && y - 1 >= 1) //y-1 x-2 { se.Add(new cor() { col = y - 1, row = x - 2 }); } if (move.col == y - 2 && move.row == x + 1 && x + 1 <= 8 && y - 2 <= 8) //y-2 x+1 { se.Add(new cor() { col = y - 2, row = x + 1 }); } if (move.col == y - 2 && move.row == x - 1 && x - 1 >= 1 && y - 2 <= 8) //y-2 x-1 { se.Add(new cor() { col = y - 2, row = x - 1 }); } break; } default: break; } foreach (var direct in se)//hareket ettiği eksende hangi taşlar var { foreach (var pc in listPieces.pieces) { if (direct.row == pc.row && direct.col == pc.col) { ps.Add(pc); } } } if (se.Count > 0) { if (ps.Count == 0)//önünde taş yoksa hareket edebilir { if (Direction == "cross" && piece.name == piece.getName.pawn) { } else { isMoveable = true; } } if (ps.Count == 1 && ps[0].color != piece.color)//önünde karşı takımın taşı varsa yenebilirmi { if (Direction == "direct" && piece.name == piece.getName.pawn) { } else { listPieces.pieces.RemoveAll(a => a.id == ps[0].id); //listeden yenen elemanı çıkartıyoruz removeID = ps[0].id; //client tarafta silinecek olan taşın id sini gönderiyoruz isMoveable = true; } } if (isMoveable == true) //hareket kabul edildiyse { piece.col = move.col; //kalenin yeni sutun değerini güncelle piece.row = move.row; //kalenin yeni satır değeri güncelle piece.isStart = true; // ilk hareket aktif et } } return(isMoveable + ";" + removeID); }
public bispo(Tabuleiro tab, cor cor) : base(tab, cor) { }
public cavalo(Tabuleiro tab, cor cor) : base(tab, cor) { }