public Tablero(Ficha [] f, PictureBox t, Timer time, PictureBox circle, PictureBox dice0, PictureBox dice1, Ficha p, RichTextBox c) { this.console = c; this.fichas = f; this.tablero = t; this.gameCheck = time; this.turnCircle = circle; this.dice0 = dice0; this.dice1 = dice1; this.previewFicha = p; this.dice = new int[2]; this.r = new Random(); this.tablero.Controls.Add(this.turnCircle); this.turnCircle.Visible = false; this.tablero.Controls.Add(p.img); this.tablero.Controls.Add(dice0); this.tablero.Controls.Add(dice1); dice0.Location = new Point(296, 345); dice1.Location = new Point(341, 345); for (int i = 0; i < fichas.Length; i++) { this.tablero.Controls.Add(fichas[i].img); sendHome(this.fichas[i]); fichas[i].img.Visible = true; fichas[i].img.BringToFront(); } dice0.BringToFront(); dice1.BringToFront(); }
public bool canMove(int team) { Ficha auxFicha = new Ficha(new PictureBox(), -1); // Needed in case that there are coins at home if (activeDices == -1) { return(true); } Ficha[] coins = getTeamCoins(team); for (int i = 0; i < coins.Length; i++) { if (coins[i].pos >= 1 && ( (this.dice0.Enabled && canMoveFicha(coins[i], dice[0], auxFicha)) || (this.dice1.Enabled && canMoveFicha(coins[i], dice[1], auxFicha)) || (selectedValue > 0 && canMoveFicha(coins[i], selectedValue, auxFicha)))) { return(true); } } log(Locale.noMove); return(false); }
public void fixPos(int pos, int team) { List <Ficha> coins = coinsAt(pos, team); if (coins.Count == 1) { if (coins[0].atHome()) { int inPos = (coins[0].pos / 100) - 1; coins[0].img.Location = Const.winPaths[coins[0].team, inPos]; } else { coins[0].img.Location = Const.cells[(coins[0].pos - 1)]; } } else if (coins.Count == 2) { Ficha first = coins[0]; Ficha second = coins[1]; int posX = first.img.Location.X; int posY = first.img.Location.Y; // At home if (first.atHome() && second.atHome()) { if (first.team == Const.GREEN || first.team == Const.BLUE) { first.img.Location = new Point(posX, posY + 20); second.img.Location = new Point(posX, posY - 20); } if (first.team == Const.RED || first.team == Const.YELLOW) { first.img.Location = new Point(posX + 20, posY); second.img.Location = new Point(posX - 20, posY); } } // Normal horizontal else if ((first.pos >= 52 && first.pos <= 59) || (first.pos >= 9 && first.pos <= 17) || (first.pos >= 18 && first.pos <= 25) || (first.pos >= 43 && first.pos <= 51)) { first.img.Location = new Point(posX, posY + 20); second.img.Location = new Point(posX, posY - 20); } // Normal vertical else { first.img.Location = new Point(posX + 20, posY); second.img.Location = new Point(posX - 20, posY); } } else { return; } }
protected void sendHome(Ficha f) { if (turn != -1 && (f.pos >= 100 || f.pos <= 0)) { return; } int freeSlot = freeHomeSlot(f.team); f.img.Location = Const.homeSlots[f.team, freeSlot]; f.pos = -1; }
private Ficha [] getTeamCoins(int team) { Ficha[] teamCoins = new Ficha[4]; for (int i = 0, j = 0; i < this.fichas.Length; i++) { if (this.fichas[i].team == team) { teamCoins[j++] = this.fichas[i]; } } return(teamCoins); }
public bool move(Ficha f, int amount) { specialMovement = false; Ficha aux = testPosition(f, amount); if (aux == null) { return(false); } else { log("Moving coin of team " + Locale.colors[f.team] + " with " + amount + " moves."); // Kill a coin if (aux.pos < 100) { List <Ficha> l = coinsAt(aux.pos, f.team); if (l.Count() == 1 && l[0].team != f.team && !isSegura(aux.pos)) { log(String.Format(Locale.coinEat, Locale.colors[f.team], Locale.colors[l[0].team])); sendHome(l[0]); selectedValue = 20; specialMovement = true; log(Locale.move20); } } lastSelectedCoin = f; int prevPos = f.pos; f.pos = aux.pos; f.img.Location = aux.img.Location; fixPos(prevPos, f.team); fixPos(f.pos, f.team); // Move 10 positions when arriving home if (f.pos == -3) { selectedValue = 10; specialMovement = true; log(Locale.coinArrived); } return(true); } }
public bool isBridges(Ficha f, int dest) { if (f.pos == dest) { return(false); } // Map -> <position, fichasAmount> Dictionary <int, int> map = new Dictionary <int, int>(); for (int i = 0; i < this.fichas.Length; i++) { if (map.ContainsKey(this.fichas[i].pos)) { map[this.fichas[i].pos]++; } else { map.Add(this.fichas[i].pos, 1); } } int origen = ((f.pos + 1) == 69) ? 1 : (f.pos + 1); bool cont = true; // log("Scanning from " + origen + " until " + dest); for (int i = origen; cont; i++ /*= (i + 1) % Const.cells.Length*/) { i = (i == 69) ? 1 : i; if (map.ContainsKey(i) && map[i] > 1) { log("There are bridges at position " + i); return(true); } if (i == dest) { cont = false; } } // log("No bridges present"); return(false); }
public bool canMoveFicha(Ficha f, int amount, Ficha previewFicha) { if (f.atHome()) { return(canMoveHome(f, ((f.pos / 100) + amount), previewFicha)); } // Console.WriteLine("Moving coin of team " + f.team + " with " + amount + " moves."); int prev = f.pos; int newPos = (f.pos + amount - 1) % Const.cells.Length; previewFicha.pos = newPos + 1; previewFicha.img.Location = Const.cells[newPos]; // Entering home if ((f.team == Const.RED && prev <= 34 && previewFicha.pos > 34) || (f.team == Const.BLUE && prev <= 17 && previewFicha.pos > 17) || (f.team == Const.YELLOW && prev > 40 && prev <= 68 && (prev + amount) > 68) || (f.team == Const.GREEN && prev <= 51 && previewFicha.pos > 51)) { int amountCasa = (prev + amount - Const.preWinCells[f.team]); // Check bridges for path outside home if (isBridges(f, Const.preWinCells[f.team])) { return(false); } return(canMoveHome(f, amountCasa, previewFicha)); } // Si hay puentes (y no en casa), devolver null (false) if (isBridges(f, newPos + 1)) { return(false); } return(true); }
public Ficha testPosition(Ficha f, int amount) { if (f.atHome()) { return(moveAtHome(f, ((f.pos / 100) + amount))); } int prev = f.pos; int newPos = (f.pos + amount - 1) % Const.cells.Length; previewFicha.pos = newPos + 1; previewFicha.img.Location = Const.cells[newPos]; // Entering home if ((f.team == Const.RED && prev <= 34 && previewFicha.pos > 34) || (f.team == Const.BLUE && prev <= 17 && previewFicha.pos > 17) || (f.team == Const.YELLOW && prev > 40 && prev <= 68 && (prev + amount) > 68) || (f.team == Const.GREEN && prev <= 51 && previewFicha.pos > 51)) { int amountCasa = (prev + amount - Const.preWinCells[f.team]); // Check bridges for path outside home if (isBridges(f, Const.preWinCells[f.team])) { return(null); } return(moveAtHome(f, amountCasa)); } // Si hay puentes (y no en casa), devolver null (false) if (isBridges(f, newPos + 1)) { return(null); } return(this.previewFicha); }
public bool isBridgesHome(Ficha f, int dest) { List <Ficha> coins = new List <Ficha>(); for (int i = 0; i < this.fichas.Length; i++) { if (this.fichas[i].team == f.team && this.fichas[i].atHome()) { coins.Add(this.fichas[i]); } } // Iterar camino casa (costoso) int currentPos = (f.pos / 100); int finalPos = (7 > dest) ? dest : 7; for (int i = currentPos + 1; i != finalPos + 1; i++) { int amount = 0; for (int j = 0; j < coins.Count; j++) { int pos = (coins[j].pos / 100); if (pos == i) { amount++; } } if (amount > 1) { log("There were bridges at position " + i); return(true); } } return(false); }
public Ficha moveAtHome(Ficha f, int pos) { if (isBridgesHome(f, pos)) { return(null); // There were bridges, could not move } if (pos == 8) { previewFicha.pos = -3; // Coin has arrived } else if (pos > 8) { return(null); // Could not move } else { previewFicha.pos = pos * 100; // Pos >= 100 means at home } previewFicha.img.Location = Const.winPaths[f.team, pos - 1]; return(this.previewFicha); }
public bool canMoveHome(Ficha f, int pos, Ficha previewFicha) { if (isBridgesHome(f, pos)) { return(false); // There were bridges, could not move } if (pos == 8) { previewFicha.pos = -3; // Coin has arrived } else if (pos > 8) { return(false); // Could not move } else { previewFicha.pos = pos * 100; // Pos >= 100 means at home } previewFicha.img.Location = Const.winPaths[f.team, pos - 1]; return(true); }
public bool preview(Ficha f, int amount) { return(testPosition(f, amount) != null); }