Ejemplo n.º 1
0
        private Move alphaBeta(State currentState)
        {
            /*if (currentPosition == null)
             * {
             *  return pickRandomMove(currentState);
             * }
             * else*/
            //{
            switch (playerNumber)
            {
            case 1:
                return(AlphaBeta.maxNextMoveID(currentState, Config.convertSettingToFloat("ai", "player_one_time")));

                //return AlphaBeta.maxNextMoveAB(currentState, Config.convertSettingToInt("ai", "player_one_depth"));
                break;

            case 2:
                return(AlphaBeta.maxNextMoveID(currentState, Config.convertSettingToFloat("ai", "player_two_time")));

                //return AlphaBeta.maxNextMoveAB(currentState, Config.convertSettingToInt("ai", "player_two_depth"));
                break;

            default:
                MainMethod.die("Player.alphaBeta : player number is not 1 or 2. It is: " + playerNumber);
                break;
            }
            //}

            return(null);
        }
Ejemplo n.º 2
0
        /**
         * Gets a (string) value from hashtables.
         *
         * @param sectionName - string - Section to look for.
         * @param optionName - string - Option to look for.
         *
         * @return string - The string value of the given option
         */
        public string getValue(string sectionName, string optionName)
        {
            if (sectionName == null)
            {
                throw new NullReferenceException();
            }
            if (optionName == null)
            {
                throw new NullReferenceException();
            }

            Hashtable temp = (Hashtable)table[sectionName];

            if (temp == null)
            {
                MainMethod.die("Error : Trikey.getValue : Section \"" + sectionName + "\" does not exist.");
            }

            string value = (string)temp[optionName];

            if (value == null)
            {
                MainMethod.die("Error : Trikey.getValue : Option: \"" + optionName + "\" from section: \"" + sectionName + "\" does not exist.");
            }

            return(value);
        }
Ejemplo n.º 3
0
        public static void setEvalFunc()
        {
            string nameOne = Config.getValue("ai", "alphabeta_eval_one");
            string nameTwo = Config.getValue("ai", "alphabeta_eval_two");

            //Set One
            if (nameOne.Equals("evade"))
            {
                playerOneEvalFunc += evade;
            }
            else if (nameOne.Equals("attack"))
            {
                playerOneEvalFunc += attack;
            }
            else if (nameOne.Equals("ratio"))
            {
                playerOneEvalFunc += ratio;
            }
            else if (nameOne.Equals("mixed"))
            {
                playerOneEvalFunc += mixed;
            }
            else if (nameOne.Equals("mixed_over_time"))
            {
                playerOneEvalFunc += mixedOverTime;
            }
            else
            {
                MainMethod.die("State.setEvalFunc : Function named: \"" + nameOne + "\" not recognized for player One.");
            }

            //Set Two
            if (nameTwo.Equals("evade"))
            {
                playerTwoEvalFunc += evade;
            }
            else if (nameTwo.Equals("attack"))
            {
                playerTwoEvalFunc += attack;
            }
            else if (nameTwo.Equals("ratio"))
            {
                playerTwoEvalFunc += ratio;
            }
            else if (nameTwo.Equals("mixed"))
            {
                playerTwoEvalFunc += mixed;
            }
            else if (nameTwo.Equals("mixed_over_time"))
            {
                playerTwoEvalFunc += mixedOverTime;
            }
            else
            {
                MainMethod.die("State.setEvalFunc : Function named: \"" + nameOne + "\" not recognized for player One.");
            }
        }
Ejemplo n.º 4
0
        private Move pickRandomMove(State currentState)
        {
            if (possibleMoves.Count == 0)
            {
                MainMethod.die(" Error : Player.pickRandomMove : the number of possible moves was zero. The game should have ended before this.");
                return(null);
            }

            return(possibleMoves[Core.numberGenerator.Next(possibleMoves.Count)]);
        }
Ejemplo n.º 5
0
        /**
         * Gets the given option from the given section and tries to convert it a char
         *
         * @param sectionName - string - The section to look for.
         * @param optionName - string - The option to retrieve
         *
         * @return - char - The option converted to a char value
         */
        public static char convertSettingToChar(string sectionName, string optionName)
        {
            string temp = getValue(sectionName, optionName);

            if (temp.Length != 1)
            {
                MainMethod.die("Error : convertSettingToChar() : Could not convert " + temp + " to char. has to many letters. Section: " + sectionName + " Option: " + optionName);
            }

            return(temp[0]);
        }
Ejemplo n.º 6
0
 //Sets the AI function to use when making moves.
 public void setAIFunc(string funcName)
 {
     if (funcName == "random")
     {
         aiFunc = pickRandomMove;
     }
     else if (funcName == "alpha_beta")
     {
         aiFunc = alphaBeta;
     }
     else
     {
         MainMethod.die("Error : Player.setAIFunc : Function name: " + funcName + " is not supported");
     }
 }
Ejemplo n.º 7
0
        /**
         * Gets the given option from the given section and tries to convert it a long
         *
         * @param sectionName - string - The section to look for.
         * @param optionName - string - The option to retrieve
         *
         * @return - long - The option converted to a long value
         */
        public static long convertSettingToLong(string sectionName, string optionName)
        {
            string temp  = getValue(sectionName, optionName);
            long   value = 0;

            try
            {
                value = Convert.ToInt64(temp);
            }
            catch (FormatException fe)
            {
                MainMethod.die("Error: Config.ConvertSettingToLong() : A Format exception has occured. Exception Message: " + fe.Message);
            }

            return(value);
        }
Ejemplo n.º 8
0
        /**
         * Gets the given option from the given section and tries to convert it a decimal
         *
         * @param sectionName - string - The section to look for.
         * @param optionName - string - The option to retrieve
         *
         * @return - decimal - The option converted to a decimal value
         */
        public static decimal convertSettingToDecimal(string sectionName, string optionName)
        {
            string  temp  = getValue(sectionName, optionName);
            decimal value = 0;

            try
            {
                value = Convert.ToDecimal(temp);
            }
            catch (FormatException fe)
            {
                MainMethod.die("Error: Config.ConvertSettingToShort() : A Format exception has occured. Exception Message: " + fe.Message);
            }

            return(value);
        }
Ejemplo n.º 9
0
 public static Player getNotCurrentPlayer()
 {
     if (currentPlayer.Equals(playerOne))
     {
         return(playerTwo);
     }
     else if (currentPlayer.Equals(playerTwo))
     {
         return(playerOne);
     }
     else
     {
         MainMethod.die("Error: Core.getNotCurrentPlayer : The current player is not player one or player two");
         return(null);
     }
 }
Ejemplo n.º 10
0
        public static float convertSettingToFloat(string sectionName, string optionName)
        {
            string temp  = getValue(sectionName, optionName);
            float  value = 0;

            try
            {
                value = float.Parse(temp);
            }
            catch (FormatException fe)
            {
                MainMethod.die("Error: Config.ConvertSettingToShort() : A Format exception has occured. Exception Message: " + fe.Message);
            }

            return(value);
        }
Ejemplo n.º 11
0
        public void makeMove(State currentState)
        {
            if (type != PlayerType.AI)
            {
                MainMethod.die("Player.makeMove : makeMove called on a human player.");
            }

            Move move = aiFunc(currentState);

            if (move == null)
            {
                return;
            }

            //Log.writeSpecial("Move sent back by AI is: " + move.ToString());

            Core.drawCube.cube[move.row, move.col, move.distance] = (byte)playerNumber;
            Move.addShadows(Core.drawCube.cube, currentPosition, move);
            currentPosition = move;
        }
Ejemplo n.º 12
0
        /**
         * Gets the given option from the given section and tries to convert it a bool
         *
         * @param sectionName - string - The section to look for.
         * @param optionName - string - The option to retrieve
         *
         * @return - bool - The option converted to a bool value
         */
        public static bool convertSettingToBool(string sectionName, string optionName)
        {
            string temp = getValue(sectionName, optionName);

            temp = temp.ToLower();

            if (temp.Equals("true") || temp.Equals("yes") || temp.Equals("t"))
            {
                return(true);
            }
            else if (temp.Equals("false") || temp.Equals("no") || temp.Equals("f"))
            {
                return(false);
            }
            else
            {
                MainMethod.die("Error : convertSettingToBool : Could not convert: " + temp + " to bool.  Section: " + sectionName + " Option: " + optionName + ".");
            }

            return(false);
        }
Ejemplo n.º 13
0
        /**
         * Parse a section of the config file.
         *
         * @param reader - StreamReader - Reader for the Config file
         * @param sectionName - string - Name of the section that is about to parsed
         * @param lineNumber - ref-int - The Current line number.
         */
        private static void parseSection(StreamReader reader, string sectionName, ref int lineNumber)
        {
            string temp = getNewLine(reader, ref lineNumber);

            if (temp == "{")
            {
                temp = getNewLine(reader, ref lineNumber);
                while (temp != null && temp != "}")
                {
                    if (String.IsNullOrWhiteSpace(temp) || temp.StartsWith("//") || temp.StartsWith("#"))
                    {
                        temp = getNewLine(reader, ref lineNumber);
                        continue;
                    }

                    string[] pieces = temp.Split(' ');

                    if (pieces.Length == 2)
                    {
                        options.addOption(sectionName, pieces[0], pieces[1]);
                    }
                    else
                    {
                        reader.Close();
                        MainMethod.die("Error: parseSection : To many words on line: \"" + lineNumber + "\". Line looks like: " + temp);
                    }

                    temp = getNewLine(reader, ref lineNumber);
                }
                if (temp == null)
                {
                    MainMethod.die("Error: Config.parseSection() : Reached the end of the file while parsing section " + sectionName);
                }
            }
            else
            {
                reader.Close();
                MainMethod.die("Error: parseSection() : Section heeaders must be followed by a \"{\" on the following line. Section Name: \"" + sectionName + "\" and on Line: \"" + (lineNumber - 1) + "\".");
            }
        }
Ejemplo n.º 14
0
        public static PlayerType getPlayerType(int playerNumber)
        {
            switch (playerNumber)
            {
            case 1:
                if (Config.getValue("players", "player_one") == "human")
                {
                    return(PlayerType.HUMAN);
                }
                else if (Config.getValue("players", "player_one") == "ai")
                {
                    return(PlayerType.AI);
                }
                else
                {
                    MainMethod.die("Error : Core.getPlayerType : player type: \"" + Config.getValue("players", "player_one") + "\" is not supported. Typo?");
                }
                break;

            case 2:
                if (Config.getValue("players", "player_two") == "human")
                {
                    return(PlayerType.HUMAN);
                }
                else if (Config.getValue("players", "player_two") == "ai")
                {
                    return(PlayerType.AI);
                }
                else
                {
                    MainMethod.die("Error : Core.getPlayerType : player type: \"" + Config.getValue("players", "player_two") + "\" is not supported. Typo?");
                }
                break;
            }

            //should never reach here but:
            return(PlayerType.HUMAN);
        }
Ejemplo n.º 15
0
        /**
         * Adds an option to the named section.
         *
         * @param sectionName - string - The section to look for.
         * @param optionName - string - The name of the Option to add
         * @param value - string - The value to give the option
         */
        public void addOption(string sectionName, string optionName, string value)
        {
            if (sectionName == null)
            {
                throw new NullReferenceException();
            }
            if (optionName == null)
            {
                throw new NullReferenceException();
            }
            if (value == null)
            {
                throw new NullReferenceException();
            }

            Hashtable temp = (Hashtable)table[sectionName];

            if (temp == null)
            {
                MainMethod.die("Error: Trikey.addOption() : section: " + sectionName + " does not exist.");
            }

            temp.Add(optionName, value);
        }
Ejemplo n.º 16
0
        //sprivate static Color4 clearColour;

        //Used to draw spheres... Not sure why it's needed...
        //public static IntPtr intptr = GLU.NewQuadric();

        /**
         * Initializes the Core of the program by initliazling everything. Failures here cause program termination
         */
        public static void init()
        {
            Config.init();

            Log.init(Config.convertSettingToInt("log", "default_level"));

            initGL();

            Cube.init();
            drawCube = new Cube();

            playerOne = new Player(1, getPlayerType(1));
            playerTwo = new Player(2, getPlayerType(2));
            switch (Config.convertSettingToInt("game", "starting_player"))
            {
            case 1:
                currentPlayer = playerOne;
                break;

            case 2:
                currentPlayer = playerTwo;
                break;

            default:
                MainMethod.die("Core.init : The starting player must either be 1 or 2, not: " + Config.convertSettingToInt("game", "starting_player"));
                break;
            }

            numberGenerator = new Random();

            simulating  = Config.convertSettingToBool("game", "simulating");
            simCount    = 0;
            simCountMax = Config.convertSettingToInt("game", "sim_count");

            State.setEvalFunc();
        }
Ejemplo n.º 17
0
        /**
         * Initializes the Cofig Manager
         */
        public static void init()
        {
            if (options != null)
            {
                Console.WriteLine("ERROR: Config.init() : Config has already been initialized..");
                return;
            }

            int          lineNumber = 0;
            StreamReader reader     = null;
            string       temp       = null;

            try
            {
                reader = new StreamReader("config.txt");
            }
            catch (FileNotFoundException fnfe)
            {
                MainMethod.die("Error: Config.init() : Unable to find Config file. Exception Method: " + fnfe.Message);
            }

            options = new Trikey();

            while (reader.Peek() > -1)
            {
                temp = getNewLine(reader, ref lineNumber);

                if (String.IsNullOrWhiteSpace(temp) || temp.StartsWith("//") || temp.StartsWith("#"))
                {
                    continue;
                }

                if (!temp.Contains("section"))
                {
                    reader.Close();
                    MainMethod.die("Error: Config.init() : Line number: \"" + lineNumber + "\" is out of place. It does not contain a comment or section start tag. Line Contents:\n" + temp);
                }

                string[] pieces = temp.Split(' ');

                if (!pieces[0].Equals("section"))
                {
                    reader.Close();
                    MainMethod.die("Error: Config.init : Line + \"" + lineNumber + "\" is out of order. \"section\" should be first string a in line. Line Contents:\n" + temp);
                }

                if (pieces.Length == 2)
                {
                    options.addSection(pieces[1]);
                    parseSection(reader, pieces[1], ref lineNumber);
                }
                else
                {
                    if (pieces.Length == 1)
                    {
                        reader.Close();
                        MainMethod.die("Error: Config.init() : Section must be named.");
                    }
                    else
                    {
                        reader.Close();
                        MainMethod.die("Error: Config.init() : This line has to many words on it. Line Number: \"" + lineNumber + "\".");
                    }
                }
            }//End WHile loop

            reader.Close();
        }//End Method