Пример #1
0
        public void InitGame()
        {
            //var game = Control.Instance;

            //this.visualization.PrintStartMessage();

            //var labyrinth = game.Setup.SetupNewLabyrinth();
            //game.State.IsInitialized = true;

            IObjectFactory       instanceFactory = new ObjectFactory();
            Labyrinth            labyrinth       = new Labyrinth(LabyrinthSize, LabyrinthSize, instanceFactory);
            GameObjectsGenerator generator       = new GameObjectsGenerator();

            generator.GenerateObjectsNew(labyrinth);

            this.visualization.PrintMessage("Labyrinth is Ready");


            this.visualization.DrawLabyrinth(labyrinth);
            MovesFactory movesFactory = new MovesFactory(labyrinth);

            while (!labyrinth.State.IsFinished)
            {
                IMoves move = this.visualization.GetUserCommand(movesFactory);
                move.Move();
                this.visualization.DrawLabyrinth(labyrinth);
            }
        }
Пример #2
0
        public void AddChildren(MatrixNode node)
        {
            string opposite;

            if (node.Moves.Count > 0)
            {
                opposite = Movable.CalcOposite(node.Moves.Last());
            }
            else
            {
                opposite = "";
            }
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    Movable aux = MovesFactory.GetInstance(i, j);
                    if (aux.IsValid(node.Matrix))
                    {
                        if (!opposite.Equals(aux.GetString()))
                        {
                            string[,] movedMatrix = aux.Move(node.Matrix);
                            MatrixNode child = new MatrixNode(movedMatrix, FinishMatrix);
                            child.Sucesors.AddRange(node.Sucesors);
                            child.Sucesors.Add(child);
                            child.Moves.AddRange(node.Moves);
                            child.Moves.Add(aux);
                            child.calculateEvaluationFunction();
                            AddInOrder(child);
                        }
                    }
                }
            }
        }
 public BoundedVistedNodesCountStrategy(IPlayersState playersState, int maxVistedNOdesCount, MovesFactory movesFactory, Func<ISearchNodeVisitor<JumpNode>, ITreeSearch<JumpNode>> searchFactory)
 {
     _bruteForceSearch = new BruteForceMoveFindingStartegy(new StopOnVisitedNodesCount<JumpNode>(maxVistedNOdesCount),
                                                           searchFactory,
                                                           playersState,
                                                           movesFactory);
 }
        public bool AddMove(string matchId, string playerId, string moveValue)
        {
            Match   match  = Matches[matchId];
            IPlayer player = match.Player1.Id == playerId ? match.Player1 : match.Player2;
            Game    game;

            if (CurrentGames.ContainsKey(matchId) && CurrentGames[matchId] != null)
            {
                game = CurrentGames[matchId];
            }
            else
            {
                game = new Game(match);
                CurrentGames[matchId] = game;
            }
            IMoves move = MovesFactory.CreateMovesFromType(MoveType);

            move.SetValue(moveValue);
            if (game.AddMove(player, move))
            {
                match.AddNewGame(game);
                CurrentGames[matchId] = null;
                return(true);
            }

            return(false);
        }
 public BoundedDepthMoveFindingStrategy(IPlayersState playersState, int maxDepth, MovesFactory movesFactory, Func<ISearchNodeVisitor<JumpNode>, ITreeSearch<JumpNode>> searchFactory)
 {
     _bruteForceSearch = new BruteForceMoveFindingStartegy(new StopOnDepthNodeVisitor<JumpNode>(maxDepth),
         searchFactory,
         playersState,
         movesFactory);
 }
Пример #6
0
 public BruteForceMoveFindingStartegy(ISearchNodeVisitor <JumpNode> defaultNodeVistor,
                                      Func <ISearchNodeVisitor <JumpNode>, IPerformMoves, TargetBorder, ITreeSearch <JumpNode> > searchFactory,
                                      IPlayersState playersState,
                                      MovesFactory movesFactory)
 {
     _defaultNodeVistor = defaultNodeVistor;
     _movesFactory      = movesFactory;
     _searchFactory     = searchFactory;
     _playersState      = playersState;
 }
 public BruteForceMoveFindingStartegy(ISearchNodeVisitor<JumpNode> defaultNodeVistor, 
     Func<ISearchNodeVisitor<JumpNode>, IPerformMoves, TargetBorder,ITreeSearch<JumpNode>> searchFactory,
     IPlayersState playersState,
     MovesFactory movesFactory)
 {
     _defaultNodeVistor = defaultNodeVistor;
     _movesFactory = movesFactory;
     _searchFactory = searchFactory;
     _playersState = playersState;
 }
Пример #8
0
 public BruteForceMoveFindingStartegy(
     ISearchNodeVisitor <JumpNode> defaultNodeVistor,
     Func <ISearchNodeVisitor <JumpNode>, ITreeSearch <JumpNode> > searchFactory,
     IPlayersState playersState,
     MovesFactory movesFactory)
 {
     _defaultNodeVistor = defaultNodeVistor;
     _movesFactory      = movesFactory;
     _searchFactory     = (visotors, perfomer, target) => searchFactory(visotors);
     _playersState      = playersState;
 }
 public BruteForceMoveFindingStartegy(
     ISearchNodeVisitor<JumpNode> defaultNodeVistor,
     Func<ISearchNodeVisitor<JumpNode>,ITreeSearch<JumpNode>> searchFactory,
     IPlayersState playersState,
     MovesFactory movesFactory)
 {
     _defaultNodeVistor = defaultNodeVistor;
     _movesFactory = movesFactory;
     _searchFactory = (visotors,perfomer, target) => searchFactory(visotors);
     _playersState = playersState;
 }
Пример #10
0
 public BoundedVistedNodesCountStrategy(
     IPlayersState playersState,
     int maxVistedNOdesCount,
     MovesFactory movesFactory,
     Func <ISearchNodeVisitor <JumpNode>, IPerformMoves, TargetBorder, ITreeSearch <JumpNode> > searchFactory)
 {
     _bruteForceSearch = new BruteForceMoveFindingStartegy(new StopOnVisitedNodesCount <JumpNode>(maxVistedNOdesCount),
                                                           searchFactory,
                                                           playersState,
                                                           movesFactory);
 }
Пример #11
0
 public CuttoffsMoveFindingStrategy(
     ISearchNodeVisitor <JumpNode> defaultNodeVistor,
     Func <ISearchNodeVisitor <JumpNode>, IPerformMoves, TargetBorder, ITreeSearch <JumpNode> > searchFactory,
     IPlayersState playersState,
     MovesFactory movesFactory)
 {
     _defaultNodeVistor = defaultNodeVistor;
     _movesFactory      = movesFactory;
     _searchFactory     = searchFactory;
     _playersState      = playersState;
     MaxVisitedNodes    = int.MaxValue;
 }
 public CuttoffsMoveFindingStrategy(
     ISearchNodeVisitor<JumpNode> defaultNodeVistor,
     Func<ISearchNodeVisitor<JumpNode>, IPerformMoves, TargetBorder,ITreeSearch<JumpNode>> searchFactory,
     IPlayersState playersState,
     MovesFactory movesFactory)
 {
     _defaultNodeVistor = defaultNodeVistor;
     _movesFactory = movesFactory;
     _searchFactory = searchFactory;
     _playersState = playersState;
     MaxVisitedNodes = int.MaxValue;
 }
Пример #13
0
 public IMoves GetUserCommand(MovesFactory factory)
 {
     Console.WriteLine("arrow");
     ConsoleKeyInfo input = Console.ReadKey();
     switch(input.Key)
     {
         case ConsoleKey.LeftArrow: return factory.MoveLeft; break;
         case ConsoleKey.RightArrow: return factory.MoveRight; break;
         case ConsoleKey.UpArrow: return factory.MoveUp; break;
         case ConsoleKey.DownArrow: return factory.MoveDown; break;
         default: throw new Exception(); break;
     }
 }
Пример #14
0
        public IMoves GetUserCommand(MovesFactory factory)
        {
            Console.WriteLine("arrow");
            ConsoleKeyInfo input = Console.ReadKey();

            switch (input.Key)
            {
            case ConsoleKey.LeftArrow: return(factory.MoveLeft); break;

            case ConsoleKey.RightArrow: return(factory.MoveRight); break;

            case ConsoleKey.UpArrow: return(factory.MoveUp); break;

            case ConsoleKey.DownArrow: return(factory.MoveDown); break;

            default: throw new Exception(); break;
            }
        }
        public List <MoveSet> GetAllowedMoves()
        {
            IMoves move = MovesFactory.CreateMovesFromType(MoveType);

            return(move.GetAllowedMoves());
        }
Пример #16
0
 public BoundedDepthMoveFindingStrategy(IPlayersState playersState, int maxDepth, MovesFactory movesFactory, Func <ISearchNodeVisitor <JumpNode>, ITreeSearch <JumpNode> > searchFactory)
 {
     _bruteForceSearch = new BruteForceMoveFindingStartegy(new StopOnDepthNodeVisitor <JumpNode>(maxDepth),
                                                           searchFactory,
                                                           playersState,
                                                           movesFactory);
 }