Ejemplo n.º 1
0
        // The ai is able to win with the next move and should prioritize this
        // Expected: Set Medium Circle 1 to Top Right Field (previous peek SmallCross1)
        // Previous Behaviour: Move Large Circle 1 to Top Right Field and loose
        // Used ai depth: 3
        // LX1   -   SX1 => MO1
        // LX2  LO2   -
        // LO1   -    -
        private static StringState WinPriority2()
        {
            StringState testState = new StringState();

            Stack <string> stringStack1 = new Stack <string>();

            stringStack1.Push("LargeCross1");
            testState.Add(Field.TopLeft, stringStack1);

            Stack <string> stringStack2 = new Stack <string>();

            stringStack2.Push("LargeCross2");
            testState.Add(Field.MiddleLeft, stringStack2);

            Stack <string> stringStack3 = new Stack <string>();

            stringStack3.Push("SmallCross1");
            stringStack3.Push("LargeCircle1");
            testState.Add(Field.BottomLeft, stringStack3);

            Stack <string> stringStack4 = new Stack <string>();

            stringStack4.Push("LargeCircle2");
            testState.Add(Field.Middle, stringStack4);

            Stack <string> stringStack5 = new Stack <string>();

            stringStack5.Push("SmallCross2");
            testState.Add(Field.TopRight, stringStack5);

            return(testState);
        }
Ejemplo n.º 2
0
        /***** TEST CASES *****/

        // The following functions serves as Test Case for Special states
        // Usement: call in first alpha beta call instead of param


        // The User win is inevitable no matter which move the ai uses
        // Expected: There will be no move result.
        //           The UI Controller shows player win announcment directly
        // Previous Behaviour: Exception
        private static StringState UserWinInevitable()
        {
            StringState testState = new StringState();

            Stack <string> stringStack1 = new Stack <string>();

            stringStack1.Push("MediumCross1");
            testState.Add(Field.TopLeft, stringStack1);

            Stack <string> stringStack2 = new Stack <string>();

            stringStack2.Push("LargeCross1");
            testState.Add(Field.Middle, stringStack2);

            Stack <string> stringStack3 = new Stack <string>();

            stringStack3.Push("LargeCross2");
            testState.Add(Field.TopRight, stringStack3);

            Stack <string> stringStack4 = new Stack <string>();

            stringStack4.Push("MediumCross2");
            stringStack4.Push("LargeCircle1");
            testState.Add(Field.MiddleLeft, stringStack4);

            Stack <string> stringStack5 = new Stack <string>();

            stringStack5.Push("LargeCircle2");
            testState.Add(Field.BottomLeft, stringStack5);

            return(testState);
        }
Ejemplo n.º 3
0
        // Return a new state with the given move on the given state with new reference
        private static StringState GetStateWithMove(StringState state, MoveString move)
        {
            // Deep clone previous state
            StringState resultState = TypeConverter.DeepCloneState(state);

            // Remove the token from the previous field (if already placed)
            resultState = RemoveTokenFromGameState(resultState, move.Token);

            // If the field already has a token
            if (resultState.ContainsKey(move.Field))
            {
                Stack <string> tokenStack = new Stack <string>(resultState[move.Field]);
                tokenStack.Push(move.Token);

                // Place the allowed Token above the old Token
                resultState.Remove(move.Field);
                resultState.Add(move.Field, tokenStack);
            }
            else
            {
                // Otherwise add the Field with a new Stack with the allowed Token
                Stack <string> tokenStack = new Stack <string>();
                tokenStack.Push(move.Token);
                resultState.Add(move.Field, tokenStack);
            }

            return(resultState);
        }
Ejemplo n.º 4
0
        // Deep Clones the given StringState to a new StringState with other Reference
        public static StringState DeepCloneState(StringState gameState)
        {
            StringState stringState = new StringState();

            foreach (var field in gameState)
            {
                Stack <string> tokenStringStack = new Stack <string>(field.Value);

                stringState.Add(field.Key, tokenStringStack);
            }

            return(stringState);
        }
Ejemplo n.º 5
0
        // Converts the given GameState with GameObjects to a StringState with Strings
        public static StringState ConvertState(GameState gameState)
        {
            StringState stringState = new StringState();

            foreach (var field in gameState)
            {
                // NOTE: this is a string stack and can't be initialized directly with gameObject stack
                Stack <string> tokenStringStack = new Stack <string>();

                // Convert Stack to Array to access not only the peek or pop the peek
                // NOTE: the stack may not be destructed (reference to current GameState)
                GameObject[] tokenGameObjectArray = field.Value.ToArray();

                // Iterate backwards to push in the right order
                for (int i = tokenGameObjectArray.Length - 1; i >= 0; i--)
                {
                    tokenStringStack.Push(tokenGameObjectArray[i].name);
                }

                stringState.Add(field.Key, tokenStringStack);
            }

            return(stringState);
        }