Exemplo n.º 1
0
 public Othello(IOthello old)
 {
     for (int i = 0; i <= old.Count; i++)
     {
         _boardList.Add(new int[8, 8]);
     }
     for (var i = 0; i < 8; i++)
     {
         for (var j = 0; j < 8; j++)
         {
             _boardList[old.Count][i, j] = old.Board[i, j];
         }
     }
     Turn  = old.Turn;
     Count = old.Count;
     _setPossiblePoints(Turn, old.GetPossiblePoints(Turn));
     Condition = old.Condition;
     EndEvent += (sender, args) =>
     {
         Condition = OthelloCondition.End;
     };
     PassEvent += (sender, args) =>
     {
         Condition = OthelloCondition.Pass;
     };
 }
Exemplo n.º 2
0
        public async Task PutAsync(IOthello othello, List <Point> ablePoints = null)
        {
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();

            if (ablePoints == null)
            {
                ablePoints = othello.GetPossiblePoints(othello.Turn);
            }
            if (ablePoints.Count == 0)
            {
                othello.Pass();
                return;
            }

            await Task.Run(() => Put(othello, ablePoints));

            sw.Stop();

            TimeSpan ts = TimeSpan.FromMilliseconds(1000) - sw.Elapsed;

            if (ts > TimeSpan.FromMilliseconds(0))
            {
                await Task.Delay(ts);
            }
        }
Exemplo n.º 3
0
        private bool _nameplay = false; // trueにするとナメプで処理が早くなります

        public Point LookAhead(IOthello Othello, int turn)
        {
            othello = Othello;
            List <int> scoreList      = new List <int>();
            var        possiblePoints = othello.GetPossiblePoints(othello.Turn);

            for (int i = 0; i < possiblePoints.Count; i++)
            {
                scoreList.Add(0);
                Othello.Put(possiblePoints[i]);
                switch (Othello.Condition)
                {
                case OthelloCondition.Wait:
                    scoreList[i] = algorithm(-10000, 10000);
                    break;

                case OthelloCondition.Pass:
                    othello.Pass();
                    scoreList[i] = algorithm(-10000, 10000);
                    othello.Back();
                    break;

                case OthelloCondition.End:
                    scoreList[i] = -(othello.GetDiscNumber(1) - othello.GetDiscNumber(-1));
                    break;
                }
                othello.Back();
                if ((scoreList[i] > 0 && othello.Turn == 1 || scoreList[i] < 0 && othello.Turn == -1) && _nameplay)
                {
                    break;
                }
            }
            if (othello.Turn == 1)
            {
                for (int i = 0; i < scoreList.Count; i++)
                {
                    if (scoreList[i] == scoreList.Max())
                    {
                        return(possiblePoints[i]);
                    }
                }
            }
            else
            {
                for (int i = 0; i < scoreList.Count; i++)
                {
                    if (scoreList[i] == scoreList.Min())
                    {
                        return(possiblePoints[i]);
                    }
                }
            }
            return(possiblePoints[0]);
        }
Exemplo n.º 4
0
        public Point LookAhead(IOthello Othello, int turn)
        {
            game        = Othello;
            AheadNumber = turn;
            List <int> scoreList = new List <int>();
            var        ableList  = game.GetPossiblePoints(game.Turn);

            for (int i = 0; i < ableList.Count; i++)
            {
                scoreList.Add(0);
                game.Put(ableList[i]);
                switch (game.Condition)
                {
                case OthelloCondition.Wait:
                    scoreList[i] = algorithm(AheadNumber - 1, -10000, 10000);
                    break;

                case OthelloCondition.Pass:
                    game.Pass();
                    scoreList[i] = algorithm(AheadNumber - 1, -10000, 10000);
                    game.Back();
                    break;

                case OthelloCondition.End:
                    scoreList[i] = -(game.GetDiscNumber(1) - game.GetDiscNumber(-1)) * 100;
                    break;
                }
                game.Back();
            }

            if (game.Turn == 1)
            {
                for (int i = 0; i < scoreList.Count; i++)
                {
                    if (scoreList[i] == scoreList.Max())
                    {
                        return(ableList[i]);
                    }
                }
            }
            else
            {
                for (int i = 0; i < scoreList.Count; i++)
                {
                    if (scoreList[i] == scoreList.Min())
                    {
                        return(ableList[i]);
                    }
                }
            }
            return(ableList[0]);
        }
Exemplo n.º 5
0
 public override void Put(IOthello othello, List <Point> ablePoints)
 {
     if (othello.Count > finalLookTurn)
     {
         var look = new FinalMakeLookAhead();
         othello.Put(look.LookAhead(othello.Clone(), 0));
     }
     else
     {
         var look = new MakeLookAhead();
         othello.Put(look.LookAhead(othello.Clone(), lookNum));
     }
 }
Exemplo n.º 6
0
 protected virtual void OnPassEvent(IOthello othello, int pass)
 {
     PassEvent?.Invoke(othello, pass);
 }
Exemplo n.º 7
0
 protected virtual void OnEndEvent(IOthello othello, int result)
 {
     EndEvent?.Invoke(othello, result);
 }
Exemplo n.º 8
0
 public override void Put(IOthello othello, List <Point> ablePoints)
 {
     othello.Put(ablePoints.First());
 }
Exemplo n.º 9
0
 public abstract void Put(IOthello othello, List <Point> ablePoints);