Example #1
0
        /// <summary>
        /// Invoke action method invokes actions on Clients Library object
        /// </summary>
        /// <param name="action"> Performed action - name of the action + direction of the move</param>
        /// <param name="currentRound"> Number of current round</param>
        void InvokeAction(PossibleAction action, int currentRound)
        {
            _history.Last().MadeMove = action.Action;
            MethodInfo method        = _cl.GetType().GetMethod(action.Action.ToString()); // INVOKE ALL ACTIONS IN QUEUE

            if (method.GetParameters().Count() == 2)
            {
                method.Invoke(_cl, new object[] { action.MoveDirection, _currentRoundNumber });
            }
            else
            {
                method.Invoke(_cl, new object[] { _currentRoundNumber });
            }
            _canMakeMove = false;
        }
Example #2
0
        public void PlayGame()
        {
            while (currentRoundNumber != allRoundsNumber)
            {
                if (canMakeMove)
                {
                    //if (currentMap.GlobalMap[myPosition.Y, myPosition.X].SmallItemNumber > 0)
                    //{
                    //    cl.PickSmallItem(currentRoundNumber);
                    //    canMakeMove = false;
                    //    //continue;
                    //}
                    //else if (currentMap.GlobalMap[myPosition.Y, myPosition.X].HasBigItem)
                    //{
                    //    cl.PickBigItem(currentRoundNumber);
                    //    canMakeMove = false;
                    //    //continue;
                    //}
                    //else if (myBigItem == true && currentMap.GlobalMap[myPosition.Y, myPosition.X].HasBigItem == false &&
                    //    currentMap.GlobalMap[myPosition.Y, myPosition.X].SmallItemNumber == 0 && currentMap.GlobalMap[myPosition.Y, myPosition.X].IsStartingPosition == false)
                    //{
                    //    cl.DropBigItem(currentRoundNumber);
                    //    canMakeMove = false;
                    //    //continue;
                    //}
                    //else if (currentMap.GlobalMap[myPosition.Y - 1, myPosition.X].Robot != null)
                    //{
                    //    cl.Punch(Directions.Up, currentRoundNumber);
                    //    canMakeMove = false;
                    //    //continue;
                    //}
                    //else if (currentMap.GlobalMap[myPosition.Y + 1, myPosition.X].Robot != null)
                    //{
                    //    cl.Punch(Directions.Down, currentRoundNumber);
                    //    canMakeMove = false;
                    //    //continue;
                    //}
                    //else if (currentMap.GlobalMap[myPosition.Y, myPosition.X + 1].Robot != null)
                    //{
                    //    cl.Punch(Directions.Right, currentRoundNumber);
                    //    canMakeMove = false;
                    //    //continue;
                    //}
                    //else if (currentMap.GlobalMap[myPosition.Y, myPosition.X - 1].Robot != null)
                    //{
                    //    cl.Punch(Directions.Left, currentRoundNumber);
                    //    canMakeMove = false;
                    //    //continue;
                    //}
                    //else if ((myPosition.X + 2 < currentMap.MapWidth - 1  && currentMap.GlobalMap[myPosition.Y, myPosition.X + 2].Robot != null) ||
                    //    (myPosition.X + 3 < currentMap.MapWidth - 1 && currentMap.GlobalMap[myPosition.Y, myPosition.X + 3].Robot != null) ||
                    //    (myPosition.X + 4 < currentMap.MapWidth - 1 && currentMap.GlobalMap[myPosition.Y, myPosition.X + 4].Robot != null))
                    //{
                    //    cl.Shoot(Directions.Right, currentRoundNumber);
                    //    canMakeMove = false;
                    //    //continue;
                    //}
                    //else if ((myPosition.X - 2 > 0 && currentMap.GlobalMap[myPosition.Y, myPosition.X - 2].Robot != null) ||
                    //    (myPosition.X - 3 > 0 && currentMap.GlobalMap[myPosition.Y, myPosition.X - 3].Robot != null) ||
                    //    (myPosition.X - 4 > 0 && currentMap.GlobalMap[myPosition.Y, myPosition.X - 4].Robot != null))
                    //{
                    //    cl.Shoot(Directions.Left, currentRoundNumber);
                    //    canMakeMove = false;
                    //    //continue;
                    //}
                    //else if ((myPosition.Y + 2 < currentMap.MapHeight - 1 && currentMap.GlobalMap[myPosition.Y + 2, myPosition.X].Robot != null) ||
                    //    (myPosition.Y + 3 < currentMap.MapHeight - 1 && currentMap.GlobalMap[myPosition.Y + 3, myPosition.X].Robot != null) ||
                    //    (myPosition.Y + 4 < currentMap.MapHeight - 1 && currentMap.GlobalMap[myPosition.Y + 4, myPosition.X].Robot != null))
                    //{
                    //    cl.Shoot(Directions.Down, currentRoundNumber);
                    //    canMakeMove = false;
                    //    //continue;
                    //}
                    //else if ((myPosition.Y - 2 > 0 && currentMap.GlobalMap[myPosition.Y - 2, myPosition.X].Robot != null) ||
                    //    (myPosition.Y - 2 > 0 && currentMap.GlobalMap[myPosition.Y - 3, myPosition.X].Robot != null) ||
                    //    (myPosition.Y - 4 > 0 && currentMap.GlobalMap[myPosition.Y - 4, myPosition.X].Robot != null))
                    //{
                    //    cl.Shoot(Directions.Up, currentRoundNumber);
                    //    canMakeMove = false;
                    //    //continue;
                    //}
                    //else
                    //{
                    //    var random = new Random();

                    //    switch (random.Next(0, 3))
                    //    {
                    //        case 0:
                    //            cl.MakeMove(Common_Library.Parts_of_map.Directions.Right, currentRoundNumber);
                    //            canMakeMove = false;
                    //            break;
                    //        case 1:
                    //            cl.MakeMove(Common_Library.Parts_of_map.Directions.Left, currentRoundNumber);
                    //            canMakeMove = false;
                    //            break;
                    //        case 2:
                    //            cl.MakeMove(Common_Library.Parts_of_map.Directions.Down, currentRoundNumber);
                    //            canMakeMove = false;
                    //            break;
                    //        case 3:
                    //            cl.MakeMove(Common_Library.Parts_of_map.Directions.Up, currentRoundNumber);
                    //            canMakeMove = false;
                    //            break;
                    //    }
                    //}


                    Random     r      = new Random();
                    var        c      = r.Next(0, possibleMoveList.Count);
                    MethodInfo method = cl.GetType().GetMethod(possibleMoveList[c].Action.ToString()); // INVOKE ALL ACTIONS IN QUEUE
                    if (method.GetParameters().Count() == 2)
                    {
                        method.Invoke(cl, new object[] { possibleMoveList[0].MoveDirection, currentRoundNumber });
                    }
                    else
                    {
                        method.Invoke(cl, new object[] { currentRoundNumber });
                    }
                    canMakeMove = false;


                    //var random = new Random();
                    //switch (random.Next(0, 6))
                    //{
                    //    case 0:
                    //        switch (random.Next(0, 3))
                    //        {
                    //            case 0:
                    //                cl.MakeMove(Common_Library.Parts_of_map.Directions.Right, currentRoundNumber);
                    //                canMakeMove = false;
                    //                break;
                    //            case 1:
                    //                cl.MakeMove(Common_Library.Parts_of_map.Directions.Left, currentRoundNumber);
                    //                canMakeMove = false;
                    //                break;
                    //            case 2:
                    //                cl.MakeMove(Common_Library.Parts_of_map.Directions.Down, currentRoundNumber);
                    //                canMakeMove = false;
                    //                break;
                    //            case 3:
                    //                cl.MakeMove(Common_Library.Parts_of_map.Directions.Up, currentRoundNumber);
                    //                canMakeMove = false;
                    //                break;
                    //        }
                    //        break;
                    //    case 1:
                    //        switch (random.Next(0, 3))
                    //        {
                    //            case 0:
                    //                cl.Shoot(Common_Library.Parts_of_map.Directions.Right, currentRoundNumber);
                    //                canMakeMove = false;
                    //                break;
                    //            case 1:
                    //                cl.Shoot(Common_Library.Parts_of_map.Directions.Left, currentRoundNumber);
                    //                canMakeMove = false;
                    //                break;
                    //            case 2:
                    //                cl.Shoot(Common_Library.Parts_of_map.Directions.Down, currentRoundNumber);
                    //                canMakeMove = false;
                    //                break;
                    //            case 3:
                    //                cl.Shoot(Common_Library.Parts_of_map.Directions.Up, currentRoundNumber);
                    //                canMakeMove = false;
                    //                break;
                    //        }
                    //        break;
                    //    case 2:
                    //        switch (random.Next(0, 3))
                    //        {
                    //            case 0:
                    //                cl.Punch(Common_Library.Parts_of_map.Directions.Right, currentRoundNumber);
                    //                canMakeMove = false;
                    //                break;
                    //            case 1:
                    //                cl.Punch(Common_Library.Parts_of_map.Directions.Left, currentRoundNumber);
                    //                canMakeMove = false;
                    //                break;
                    //            case 2:
                    //                cl.Punch(Common_Library.Parts_of_map.Directions.Down, currentRoundNumber);
                    //                canMakeMove = false;
                    //                break;
                    //            case 3:
                    //                cl.Punch(Common_Library.Parts_of_map.Directions.Up, currentRoundNumber);
                    //                canMakeMove = false;
                    //                break;
                    //        }
                    //        break;


                    //    case 3:
                    //        cl.PickBigItem(currentRoundNumber);
                    //        canMakeMove = false;
                    //        break;
                    //    case 4:
                    //        cl.PickSmallItem(currentRoundNumber);
                    //        canMakeMove = false;
                    //        break;
                    //    case 5:
                    //        cl.DropBigItem(currentRoundNumber);
                    //        canMakeMove = false;
                    //        break;
                    //    case 6:
                    //        cl.Rest(currentRoundNumber);
                    //        canMakeMove = false;
                    //        break;
                    //}
                }
            }
        }