Esempio n. 1
0
        private MoveCandidate analyze(int depth, int field, PositionContext position)
        {
            ConsoleLogger.LogDepth(depth);
            ConsoleLogger.LogMove(position);
            if (depth == Settings.MaxDepth)
            {
                MoveCandidate candidate = new MoveCandidate(field, position);
                PositionController.MakeMove(position, field);
                candidate.Evaluation = evaluate(position);
                ConsoleLogger.Log(candidate.Evaluation.ToString());
                computedVariation++;
                return(candidate);
            }

            States move = position.Move;

            List <int> candidates = FindCandidates(position);

            if (candidates.Count == 0)
            {
                ConsoleLogger.Log("! nie znaleziono ruchow kandydatow!");
            }

            ConsoleLogger.Log("Ilość kandydatów: " + candidates.Count);

            List <MoveCandidate> moveCandidates = new List <MoveCandidate>();

            foreach (var i in candidates)
            {
                PositionContext newPosition = PositionContextFactory.CreatePositionContext(position);
                PositionController.MakeMove(newPosition, i);
                MoveCandidate candidate = analyze(depth + 1, i, newPosition);
                moveCandidates.Add(candidate);
            }

            var bestCandidate = getBest(moveCandidates, move);

            ConsoleLogger.Log("Z " + candidates.Count + " wariantow wybrano: " + bestCandidate.Evaluation.ToString());
            return(bestCandidate);
        }
Esempio n. 2
0
        public override MoveCandidate Play()
        {
            int dimension = (int)Settings.BoardSize;

            // TODO
            // very, very stupid clause
            while (true)
            {
                int fieldIndex = this.randomNumber(0, dimension * dimension - 1);

                if (this.gameContext.GetField(fieldIndex).FieldState.Equals(States.Empty))
                {
                    MoveInfo logInfo = new MoveInfo("Wylosowalem taki ruch=" + fieldIndex);

                    this.gameContext.Info = logInfo;

                    MoveCandidate move = new MoveCandidate(fieldIndex);

                    return(move);
                }
            }
        }