Beispiel #1
0
 //Return true is already exist
 // false if non-exist
 public override bool addToMap(Playfield state)
 {
     float key = getHashkey(state);
     //Helpfunctions.Instance.logg("end key = " + key);
     if (TTable.ContainsKey(key))
     {
         foreach (Playfield existState in TTable[key])
         {
             if (existState.isHandEqual(state, true))
             {
                 return true;
             }
         }
         if (TTable[key][0].getBoardValue() < state.getBoardValue())
         {
             //Helpfunctions.Instance.logg("orig board " + TTable[key][0].getBoardValue());
             //TTable[key][0].debugMinions();
             //Helpfunctions.Instance.logg("new board " + state.getBoardValue());
             //state.debugMinions();
             TTable[key][0] = state;
         } 
         return false;
     }
     else
     {
         TTable.Add(key, new List<Playfield>());
         TTable[key].Add(state);
     }
     return false;
 }
Beispiel #2
0
        public float sample(Node p)
        {
            Playfield startState = new Playfield(p.state);
            Action move = null;
            int turn = p.depth;

            //Helpfunctions.Instance.logg("turn: " + turn);

            int score = startState.getGameResult();
            while (score == -1)
            {
                //List<Action> moves = Movegenerator.Instance.getMoveList(startState, false, false, true);
                //if (move != null)
                //{
                //GameManager.Instance.moveCount++;
                //if (GameManager.Instance.moveCount == 562)
                //{
                //    int debug = 1;
                //}
                    //var milliseconds = (DateTime.Now - DateTime.MinValue).TotalMilliseconds;
                    Movegenerator.Instance.getMoveListForPlayfield(startState, false);
                    //double time = (DateTime.Now - DateTime.MinValue).TotalMilliseconds - milliseconds;
                    //GameManager.Instance.myTimer += time;
                    //Helpfunctions.Instance.logg("my:" + time + " total:" + GameManager.Instance.myTimer);


                    //milliseconds = (DateTime.Now - DateTime.MinValue).TotalMilliseconds;
                    //List<Action> bruteForceMoves = Movegenerator.Instance.getMoveList(startState, false, true, true);
                    //time = (DateTime.Now - DateTime.MinValue).TotalMilliseconds - milliseconds;
                    //GameManager.Instance.sfTimer += time;
                    //Helpfunctions.Instance.logg("sf:" + time + " total:" + GameManager.Instance.sfTimer);

                    //if (bruteForceMoves.Count != startState.moveList.Count) {
                    //    startState.printBoard();
                    //    int debug = 1;
                    //    Helpfunctions.Instance.logg("BF Move List:------------------------------------");
                    //    foreach (Action action in bruteForceMoves)
                    //    {
                    //        action.print();
                    //    }
                    //    startState.printMoveList();
                    //}
                //}
                //Helpfunctions.Instance.logg("Count: " + startState.moveList.Count);
                if (startState.moveList.Count == 0)
                {
                    startState.endTurn(false, false);
                    //Helpfunctions.Instance.logg("Turn = " + startState.isOwnTurn);
                    if (!isEndReached)
                    {
                        //if (startState.isOwnTurn && this.playerSide == 1 || !startState.isOwnTurn && this.playerSide == 0)
                        //{
                        //    turn++;
                        //    //Helpfunctions.Instance.logg("Turn++");
                        //}
                        turn++;
                        move = null;
                        if (turn == rolloutDepth) //evaluate at deapth == 5
                        {
                            //startState.printBoard();
                            float value = startState.getBoardValue();
                            //Helpfunctions.Instance.logg("value = " + value);
                            if (value > bestValue)
                            {
                                bestBoard = new Playfield(startState);
                                bestValue = value;
                            }
                            return value;
                        }
                    }
                }
                else
                {
                    move = startState.moveList[GameManager.getRNG().Next(startState.moveList.Count)];
                    startState.doAction(move);
                }
                score = startState.getGameResult();
            }

            isEndReached = true;
            if (playerSide == score)
            {
                return 1;
            }
            return 0;
        }