private int CompareMoves(Move left, Move right) { // Maaliin jos pääsee if (IsInGoal(left.EndPosition) && !IsInGoal(left.StartPosition)) { if (!IsInGoal(right.EndPosition) || IsInGoal(right.StartPosition)) { return -1; } } else if (IsInGoal(right.EndPosition) && !IsInGoal(left.StartPosition)) { return 1; } // Syö, poistu kotipesästä, tuplaa aina kuin voit if (left.Type != right.Type) { MoveType[] preferences = { MoveType.Eat, MoveType.OutOfHome, MoveType.DoubleUp, MoveType.Move, MoveType.SelfTackle }; foreach(MoveType preference in preferences) { if (left.Type == preference) return -1; if (right.Type == preference) return 1; } } return 0; }
public int SelectMove(Situation situation, Move[] moves, Piece side, int roll) { Move[] c = new Move[moves.Length]; Array.Copy(moves, c, moves.Length); Array.Sort<Move>(c, CompareMoves); return Array.IndexOf<Move>(moves, c[0]); }
public int SelectMove(Situation situation, Move[] moves, Piece side, int roll) { Console.WriteLine("Side: " + side); Console.WriteLine("Roll: " + roll); Console.WriteLine("Situation: "); Console.WriteLine(situation.ToString()); int selectedMove = -1; do { Console.WriteLine("Moves"); for (int i = 0; i < moves.Length; i++) { Console.WriteLine(i + ": " + moves[i].ToString()); } Console.WriteLine("Select move: "); selectedMove = Convert.ToInt32(Console.ReadLine()); } while (selectedMove < 0 || selectedMove >= moves.Length); return selectedMove; }
// Event handlers for threadedlimakegame private void SelectMoveHandler(Situation situation, Move[] moves, Piece side, int roll) { this.availableMoves = moves; this.currentSituation = situation; for (int i = 0; i < moves.Length; i++) { Move move = moves[i]; pieces[move.Piece].Movable = true; if (situation.groupingDict.ContainsKey(move.Piece)) { foreach (int otherPiece in situation.groupingDict[move.Piece]) { if (otherPiece != move.Piece) { pieces[otherPiece].Movable = true; } } } } }
public int SelectMove(Situation situation, Move[] moves, Piece side, int roll) { return rand.Next(moves.Length); }
void IGameDisplay.DispĺayMove(Move move) { Console.WriteLine(move.ToString()); }
int IPlayer.SelectMove(Situation situation, Move[] moves, Piece side, int roll) { selectedMove = -1; moveARE.Reset(); Deployment.Current.Dispatcher.BeginInvoke(delegate() { SelectMove(situation, moves, side, roll); }); moveARE.WaitOne(); return selectedMove; }
void IGameDisplay.DispĺayMove(Move move) { if (DisplayMove != null) { Deployment.Current.Dispatcher.BeginInvoke(delegate() { DisplayMove(move); }); Delay(false); } }
public HistoryEntry(Situation sit, Move move) { this.situation = sit; this.move = move; }
void IGameDisplay.DispĺayMove(Move move) { }