public void pruebaColocaFichasBot() { Ficha ficha1 = new Ficha(); ficha1.color = "Red"; ficha1.forma = "▲"; string jsonString = JsonConvert.SerializeObject(ficha1); tablero.Rows[15][15] = jsonString; ficha1.color = "Red"; ficha1.forma = "◆"; tablero.Rows[14][15] = JsonConvert.SerializeObject(ficha1); ficha1.color = "Blue"; ficha1.forma = "◆"; tablero.Rows[14][14] = JsonConvert.SerializeObject(ficha1); tableroAnterior = tablero.Copy(); ColocaFichaBotSmart(); //tableroAnterior = tablero.Copy(); //_plays.Clear(); //ColocaFichaBotDummie(); string aa = "a"; jugadores[1].setFichasJugador(GetBolsaTotalFichas()); jugadores[2].setFichasJugador(GetBolsaTotalFichas()); string a = "a"; }
public void printTablero() { DataTable tablero = juego.GetTablero(); DataTable tableroAnterior = juego.tableroAnterior; string p = ""; //List<Controllers.Ficha> listaFichas; for (int i = 0; i < 30; i++) { for (int j = 0; j < 30; j++) { if (!tablero.Rows[i][j].ToString().Equals(tableroAnterior.Rows[i][j].ToString())) { Controllers.Ficha fichaObj = JsonConvert.DeserializeObject <Controllers.Ficha>(tablero.Rows[i][j].ToString()); colocarFichasBots(i, j, fichaObj, true); } else { if (!tablero.Rows[i][j].ToString().Equals("0")) { Controllers.Ficha fichaObj = JsonConvert.DeserializeObject <Controllers.Ficha>(tablero.Rows[i][j].ToString()); colocarFichasBots(i, j, fichaObj, false); } } } } }
public void actualizarFichasHumano() { Controllers.Ficha ficha = new Controllers.Ficha(); ficha.color = color; ficha.forma = forma; juego.ColocaFicha(ficha, x, y); fichasJugador3 = juego.GetJugadores()[0].fichasJugador; colocarFichasHumano(); string p = ""; }
public bool PlayBotSmart(Ficha piece, int x, int y) { if (ValidacionJuegoTurno_Aux(piece, x, y)) { tablero.Rows[x][y] = JsonConvert.SerializeObject(piece); tablero = tablero.Copy(); Pos pos = new Pos(); pos.x = x; pos.y = y; _plays.Add(pos); return(true); } else { return(false); } }
// funcion encargada de colocar las fichas de los bots public void colocarFichasBots(int x, int y, Controllers.Ficha ficha, bool flag) { //if (ultimaFicha != null) //{ // ultimaFicha.BackColor = Color.White; //} Button boton = (Button)tableLayoutPanel1.GetControlFromPosition(y, x); boton.Text = ficha.forma; switch (ficha.color) { case "Red": boton.ForeColor = Color.Red; break; case "Yellow": boton.ForeColor = Color.Yellow; break; case "Green": boton.ForeColor = Color.Green; break; case "Cyan": boton.ForeColor = Color.Cyan; break; case "Magenta": boton.ForeColor = Color.Magenta; break; case "Blue": boton.ForeColor = Color.Blue; break; } boton.TextAlign = ContentAlignment.MiddleCenter; boton.Font = new Font(boton.Font.FontFamily, 30); if (flag) { boton.BackColor = Color.LightGreen; } else { boton.BackColor = Color.White; } }
public void ColocaFicha(Ficha ficha, int X, int Y) { string jsonString = JsonConvert.SerializeObject(ficha); tablero.Rows[X][Y] = jsonString; Pos pos = new Pos(); pos.x = X; pos.y = Y; _plays.Add(pos); jugadores[0].puntaje += score(); jugadores[0].puntosUltimaJugada = score(); for (int i = 0; i < jugadores[0].fichasJugador.Count(); i++) { if (jugadores[0].fichasJugador[i].color.Equals(ficha.color) && jugadores[0].fichasJugador[i].forma.Equals(ficha.forma)) { jugadores[0].fichasJugador.RemoveAt(i); jugadores[0].setFichasJugador(bolsaTotalFichas); int d = 1; } int stop = 1; } }
public void PlayBotDummie(Ficha piece, int x, int y) { if (ValidacionJuegoTurno_Aux(piece, x, y)) { //Console.WriteLine("Error"); tablero.Rows[x][y] = JsonConvert.SerializeObject(piece); tablero = tablero.Copy(); List <Ficha> tiles = jugadores[1].fichasJugador; int posI = tiles.IndexOf(piece); tiles.RemoveAt(posI); Pos pos = new Pos(); pos.x = x; pos.y = y; _plays.Add(pos); jugadores[1].puntaje += score(); jugadores[1].puntosUltimaJugada = score(); //Qwirkle.colocarFichasBots(x, y, piece); int stop = 0; } //self._board[y][x] = piece //self._plays.append((x, y)) //self._pad_board() }
//DETERMINA SI LA FICHA SE PUEDE COLOCAR; public bool filaValida(List <string> rowStrings) { List <Ficha> row = new List <Ficha>(); List <string> shapes = new List <string>(); List <string> colors = new List <string>(); foreach (var item in rowStrings) { Ficha fichaObj = JsonConvert.DeserializeObject <Ficha>(item); row.Add(fichaObj); } if (row.Count == 1) { return(true); } bool colores = true; foreach (var color in row) { if (!color.color.Equals(row[0].color)) { colores = false; } } bool formas = true; foreach (var forma in row) { if (!forma.forma.Equals(row[0].forma)) { formas = false; } } //SI TODA LA FILA ES EL MISMO COLOR ENTRA. if (colores) { for (int i = 0; i < row.Count; i++) { if (shapes.Contains(row[i].forma)) { return(false); } else { shapes.Add(row[i].forma); } } } //SI TODA LA FILA ES LA MISMA FORMA ENTRA. if (formas) { for (int i = 0; i < row.Count; i++) { if (colors.Contains(row[i].color)) { return(false); } else { colors.Add(row[i].color); } } } else { return(false); } return(true); }
public bool ValidacionJuegoTurno_Aux(Ficha ficha, int x, int y) { if (!GetBoolPosTablero(x, y)) { return(false); } List <bool> fichasAdyacentes = new List <bool>(); if (y - 1 >= 0) { fichasAdyacentes.Add(GetBoolPosTablero(x, y - 1)); } if (y + 1 < tablero.Rows.Count) { fichasAdyacentes.Add(GetBoolPosTablero(x, y + 1)); } if (x - 1 >= 0) { fichasAdyacentes.Add(GetBoolPosTablero(x - 1, y)); } if (x + 1 < 30) { fichasAdyacentes.Add(GetBoolPosTablero(x + 1, y)); } int contadorTrue = 0; foreach (var item in fichasAdyacentes) { if (item) { contadorTrue += 1; } } if (contadorTrue == fichasAdyacentes.Count) { return(false); } List <Pos> plays = new List <Pos>(); foreach (var item in _plays) { plays.Add(new Pos { x = item.x, y = item.y }); } //Se valida si el array _plays contiene mas de una ficha, para crear la conexion. if (plays.Count > 0) { bool check_horizontal = true; bool check_vertical = true; if (plays.Count > 1) { if (plays[0].x == plays[1].x) { check_horizontal = false; } if (plays[0].y == plays[1].y) { check_vertical = false; } } bool in_plays = false; //Verifica si existen fichas horizontalmente if (check_horizontal) { int t_x1 = x; while (t_x1 - 1 >= 0 && !GetBoolPosTablero(t_x1 - 1, y)) { t_x1 -= 1; foreach (var item in plays) { if (item.x == t_x1 && item.y == y) { in_plays = true; } } } t_x1 = x; while (t_x1 + 1 < 30 && !GetBoolPosTablero(t_x1 + 1, y)) { t_x1 += 1; foreach (var item in plays) { if (item.x == t_x1 && item.y == y) { in_plays = true; } } } } //Verifica si existen fichas verticalmente if (check_vertical) { int t_y1 = y; while (t_y1 - 1 >= 0 && !GetBoolPosTablero(x, t_y1 - 1)) { t_y1 -= 1; foreach (var item in plays) { if (item.x == x && item.y == t_y1) { in_plays = true; } } } t_y1 = y; while (t_y1 + 1 < tablero.Rows.Count && !GetBoolPosTablero(x, t_y1 + 1)) { t_y1 += 1; foreach (var item in plays) { if (item.x == x && item.y == t_y1) { in_plays = true; } } } } if (!in_plays) { return(false); } } if (ficha is null) { return(true); } List <string> row = new List <string>(); row.Add(JsonConvert.SerializeObject(ficha)); int t_x = x + 1; while (t_x < 30 && !GetBoolPosTablero(t_x, y)) { row.Add(tablero.Rows[t_x][y].ToString()); t_x += 1; } t_x = x - 1; while (t_x >= 0 && !GetBoolPosTablero(t_x, y)) { row.Add(tablero.Rows[t_x][y].ToString()); t_x -= 1; } bool pruebaRow = filaValida(row); if (!filaValida(row)) { return(false); } //return true; //Obtiene y verifica las fichas verticales. row.Clear(); row.Add(JsonConvert.SerializeObject(ficha)); int t_y = y + 1; while (t_y < tablero.Rows.Count && !GetBoolPosTablero(x, t_y)) { row.Add(tablero.Rows[x][t_y].ToString()); t_y += 1; } t_y = y - 1; while (t_y >= 0 && !GetBoolPosTablero(x, t_y)) { row.Add(tablero.Rows[x][t_y].ToString()); t_y -= 1; } if (!filaValida(row)) { return(false); } return(true); }