Пример #1
0
 private void UpdateGhostLocation(IMoveEvaluatorContext moveEvaluatorContext, MoveEvaluationResult result)
 {
     if (!GhostLocations.Any())
     {
         //Find the ghost location
         for (int i = 0; i < moveEvaluatorContext.FieldMap.Count; i++)
         {
             for (int j = 0; j < moveEvaluatorContext.FieldMap[i].Count; j++)
             {
                 if (moveEvaluatorContext.FieldMap[i][j].DisplayText == "G")
                 {
                     GhostLocations.Add((Row: i, Column: j, MapEntity: moveEvaluatorContext.FieldMap[i][j]));
                 }
             }
         }
     }
     else
     {
         var changedLocations = 0;
         for (int i = 0; i < moveEvaluatorContext.FieldMap.Count; i++)
         {
             for (int j = 0; j < moveEvaluatorContext.FieldMap[i].Count; j++)
             {
                 if (moveEvaluatorContext.FieldMap[i][j].DisplayText == "" && i != moveEvaluatorContext.NextRow &&
                     j != moveEvaluatorContext.NextColumn)
                 {
                     result.UpdatdEntities.Add((Row: i, Column: j, UpdatedEntity: GhostLocations[changedLocations].MapEntity));
                     result.UpdatdEntities.Add((Row: GhostLocations[changedLocations].Row, Column: GhostLocations[changedLocations].Column, UpdatedEntity: new MapEntity()));
                     GhostLocations[changedLocations] = (i, j, GhostLocations[changedLocations].MapEntity);
Пример #2
0
        public MoveEvaluationResult EvaluateMove(IMoveEvaluatorContext moveEvaluatorContext)
        {
            var result = new MoveEvaluationResult();

            var nextEntity = moveEvaluatorContext.FieldMap[moveEvaluatorContext.NextRow][moveEvaluatorContext.NextColumn];

            if (nextEntity.IsMoveAllowedOnThis)
            {
                if (nextEntity.DisplayText == "X")
                {
                    if (!HasWeapon)
                    {
                        result.UpdatdEntities.Add((Row: moveEvaluatorContext.NextRow, Column: moveEvaluatorContext.NextColumn, UpdatedEntity: new MapEntity()));
                        HasWeapon = true;
                    }
                    result.EvaluatedScore = moveEvaluatorContext.CurrentScore;
                    result.IsMovePossible = true;
                }
                else if (nextEntity.DisplayText == "G" || nextEntity.DisplayText == "Z")
                {
                    if (HasWeapon)
                    {
                        result.UpdatdEntities.Add((Row: moveEvaluatorContext.NextRow, Column: moveEvaluatorContext.NextColumn, UpdatedEntity: new MapEntity()));
                        result.EvaluatedScore = nextEntity.DisplayText == "Z" ? moveEvaluatorContext.CurrentScore + 10 : moveEvaluatorContext.CurrentScore + 20;
                        HasWeapon             = false;
                    }
                    else
                    {
                        result.EvaluatedScore = 0;
                    }
                    result.IsMovePossible = true;
                }
                else if (nextEntity.DisplayText == "Ex")
                {
                    result.IsMovePossible = true;
                    result.EvaluatedScore = moveEvaluatorContext.CurrentScore;
                    result.IsGameWon      = true;
                }
                else if (nextEntity.DisplayText == "")
                {
                    result.IsMovePossible = true;
                    result.EvaluatedScore = moveEvaluatorContext.CurrentScore;
                }
            }
            else
            {
                if (nextEntity.DisplayText == "W")
                {
                    result.IsMovePossible = false;
                    result.EvaluatedScore = moveEvaluatorContext.CurrentScore;
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }

            UpdateGhostLocation(moveEvaluatorContext, result);

            return(result);
        }