public chip(int beginX = 0, int beginY = 0, int life = 1, cell[,] costMap = null) { BeginX = beginX; BeginY = beginY; Life = life; CurrentState = new cell(BeginX, BeginY, Life); }
//paintig chips private void chipPaint(double Width, double Height) { int x = game.MapSizeX; int y = game.MapSizeY; CurrentCellSize = (Width - otstup) / x; if ((Height - otstup) / y < CurrentCellSize) { CurrentCellSize = (Height - otstup) / y; } if (CurrentCellSize < 2 * thick) { CurrentCellSize = 2 * thick; } cell a = game.GetPlayer1CurrentState(); AddElps(a.X, a.Y, new SolidColorBrush(Color.FromRgb(255, 180, 0))); AddTBL(a.X, a.Y, "1, L =" + a.Price.ToString()); for (int i = 0; i < game.GetPlayer2Count(); i++) { a = game.GetPlayer2CurrentState(i + 1); AddElps(a.X, a.Y, new SolidColorBrush(Color.FromRgb(255, 180, 220))); AddTBL(a.X, a.Y, "2, L =" + a.Price.ToString()); } }
public static void Clear() { IsEndInitiated = false; IsMapInitiated = false; gameMap = null; End = new cell(0, 0); }
private void Player2CurrentChip_SelectionChanged(object sender, SelectionChangedEventArgs e) { cell a = game.GetPlayer2CurrentState(Convert.ToInt32(Player2CurrentChipLB.SelectedValue)); XPlayer2TB.Text = (SCM.InvX(a.X)).ToString(); YPlayer2TB.Text = (SCM.InvY(a.Y)).ToString(); } //check
//get the cell number index where you can go for one time from thisCell public cell GetOneCell(cell thisCell, int index) { cell b = new cell(); b.X = oneTime[Number(thisCell.X, thisCell.Y)][index] % SizeX; b.Y = (oneTime[Number(thisCell.X, thisCell.Y)][index] - b.X) / SizeX; b.Price = costPath[Number(thisCell.X, thisCell.Y), oneTime[Number(thisCell.X, thisCell.Y)][index]].Key; return(b); }
private tetra TheWorstCell(chip player1, chip[] player2) { tetra Min = new tetra(); for (int i = 0; i < player2.Length; i++) { if (player2[i].GetCostPath(player2[i].CurrentState, player1.CurrentState) <= 1) { tetra ans = new tetra(player1.CurrentState, Rating(player1.CurrentState, player1, player2), depth, false, true, i); bad = false; good = false; return(ans); } if (player2[i].GetCostPath(player2[i].CurrentState, End) == 1) { tetra ans = new tetra(End, Rating(player1.CurrentState, player1, player2), depth, true, false, i); bad = false; good = false; return(ans); } for (int j = 0; j < player2[i].GetOneTimeCellCount(player2[i].CurrentState); j++) { cell a = player2[i].CurrentState; player2[i].CurrentState = player2[i].GetOneTimeCell(a, j); tetra b = TheBestCell(player1, player2); player2[i].CurrentState = a; if (b.Bad) { if (!Min.Bad || Min.Depth > b.Rating || Min.Depth == b.Depth && Min.Rating > b.Rating) { Min = b; Min.Index = i; Min.Cell = player2[i].GetOneTimeCell(a, j); } } else if (b.Good) { if (j == 0 || Min.Good && (Min.Depth < b.Depth || Min.Depth == b.Depth && Min.Rating > b.Rating)) { Min = b; Min.Index = i; Min.Cell = player2[i].GetOneTimeCell(a, j); } } else if (j == 0 || !Min.Bad && (Min.Good || b.Rating < Min.Rating)) { Min = b; Min.Index = i; Min.Cell = player2[i].GetOneTimeCell(a, j); } } } return(Min); }
public tetra(cell thisCell, int rating, int depth, bool good, bool bad, int index = 0) : this() { Cell = thisCell; Rating = rating; Good = good; Bad = bad; Index = index; Depth = depth; }
public void InitPathWithWarriors(cell begin, chip[] warriorPlayer) { int number = warriorPlayer.Length; cell[] player2Chips = new cell[number]; for (int i = 0; i < number; i++) { player2Chips[i] = warriorPlayer[i].CurrentState; } thisPath.InitPathWithWarriors(begin, ref player2Chips); }
//get the List od cells - the path from begin to end public List <cell> GetParent(cell begin, cell end) { List <cell> parentMap = new List <cell>(); parentMap.Add(end); while (end != begin) { int number = parent[Number(begin), Number(end)]; end = Map[number % SizeX, (number - number % SizeX) / SizeX]; parentMap.Add(end); } parentMap.Reverse(); return(parentMap); }
//initializate path from cell begin for current map and life considering warriors public void InitPathWithWarriors(cell begin, ref cell[] warriors) { for (int i = 0; i < size; i++) { used[i] = false; costPath[Number(begin), i] = new pair(max, 0); } for (int j = 0; j < warriors.Length; j++) { used[Number(warriors[j])] = true; } SetPath(Number(begin)); }
private int Rating(cell thisCell, chip player1, chip[] player2) { int ans = -player1.GetCostPath(thisCell, End); for (int i = 0; i < player2.Length; i++) { if (player2[i].GetCostPath(player2[i].CurrentState, thisCell) == 1 || player2[i].GetCostPath(player2[i].CurrentState, End) == 1) { bad = true; } ans += player2[i].GetCostPath(player2[i].CurrentState, thisCell); ans += player2[i].GetCostPath(player2[i].CurrentState, End); } if (!bad && -ans <= 1) { good = true; } return(ans); }
//get the cost of the path from begin to end public int GetCostPath(cell begin, cell end) { return(costPath[Number(begin.X, begin.Y), Number(end.X, end.Y)].Key); }
public int GetOneTimeCellCount(cell a) { return(thisPath.GetOneCount(a)); }
public cell GetOneTimeCell(cell a, int index) { return(thisPath.GetOneCell(a, index)); }
public int GetCostPath(cell begin, cell end) { return(thisPath.GetCostPath(begin, end)); }
private tetra TheBestCell(chip player1, chip[] player2) { player1.InitPathWithWarriors(player1.CurrentState, player2); if (player1.GetCostPath(player1.CurrentState, End) == 1) { tetra ans = new tetra(End, Rating(player1.CurrentState, player1, player2), depth + 1, true, false); bad = false; good = false; return(ans); } if (depth < maxDepth) { depth++; tetra Max = new tetra(); for (int i = 0; i < player1.GetOneTimeCellCount(player1.CurrentState); i++) { cell a = player1.CurrentState; player1.CurrentState = player1.GetOneTimeCell(a, i); tetra b = TheWorstCell(player1, player2); player1.CurrentState = a; player1.InitPathWithWarriors(player1.CurrentState, player2); if (b.Good) { if (!Max.Good || Max.Depth > b.Depth || Max.Depth == b.Depth && Max.Rating < b.Rating) { Max = b; Max.Cell = player1.GetOneTimeCell(a, i); } } else if (b.Bad) { if (i == 0 || Max.Bad && (Max.Depth < b.Depth || Max.Depth == b.Depth && Max.Rating < b.Rating)) { Max = b; Max.Cell = player1.GetOneTimeCell(a, i); } } else if (i == 0 || !Max.Good && (Max.Bad || b.Rating > Max.Rating)) { Max = b; Max.Cell = player1.GetOneTimeCell(a, i); } } depth--; return(Max); } else { tetra Max = new tetra(); for (int i = 0; i < player1.GetOneTimeCellCount(player1.CurrentState); i++) { cell thisCell = player1.GetOneTimeCell(player1.CurrentState, i); player1.InitPathWithWarriors(thisCell, player2); int thisRating = Rating(thisCell, player1, player2); if (good) { if (!Max.Good || Max.Rating < thisRating) { good = false; Max.Good = true; Max.Bad = false; Max.Cell = thisCell; Max.Rating = thisRating; Max.Depth = depth + 2; } } else if (bad) { if (i == 0 || Max.Bad && Max.Rating < thisRating) { bad = false; Max.Good = false; Max.Bad = true; Max.Cell = thisCell; Max.Rating = thisRating; Max.Depth = depth + 1; } } else if (i == 0 || !Max.Good && (Max.Bad || Max.Rating < thisRating)) { Max.Bad = false; Max.Rating = thisRating; Max.Cell = thisCell; Max.Depth = depth + 1; } } return(Max); } }
public List <cell> GetParent(cell a, cell b) { return(thisPath.GetParent(a, b)); }
//get number of cells where you can go for one time from thisCell public int GetOneCount(cell thisCell) { return(oneTime[Number(thisCell.X, thisCell.Y)].Count); }
private int Number(cell a) { return(a.X + a.Y * SizeX); }