コード例 #1
0
ファイル: Cards.cs プロジェクト: tjosgood/TurnSim
        public override List <PossibleMove> PossibleMoves(int x, int y, BoardClass Board, int PlayerID)
        {
            var m = Board.ShadowLastPlayedCard.PossibleMoves(x, y, Board, PlayerID);

            m.ForEach(o => o.isShadow = true);
            return(m);
        }
コード例 #2
0
ファイル: Cards.cs プロジェクト: tjosgood/TurnSim
        private PossibleMove CheckPath(int x, int y, int xoff, int yoff, BoardClass Board)
        {
            int xcur = x, ycur = y;
            var gaplen = 0;

            for (int steps = 0; steps < 100; steps++)
            {
                xcur += xoff;
                ycur += yoff;

                if (!Board.InBounds(xcur, ycur))
                {
                    return(null);
                }
                var valid = Board.IsWalkable(xcur, ycur);

                if (Board.Tiles[xcur, ycur].Type != CardType.Empty)
                {
                    if (gaplen > 0 && valid)
                    {
                        return new PossibleMove()
                               {
                                   FromX = x, FromY = y, ToX = xcur, ToY = ycur, ScoreValue = Board.Tiles[xcur, ycur].ScoreValue, Card = this, Destination = Board.Tiles[xcur, ycur]
                               }
                    }
                    ;
                    return(null);
                }

                gaplen++;
            }
            return(null);
        }
コード例 #3
0
ファイル: Cards.cs プロジェクト: tjosgood/TurnSim
        public override List <PossibleMove> PossibleMoves(int x, int y, BoardClass Board)
        {
            var Res = new List <PossibleMove>();

            Res.AddRange(Walk(x, y, 1, true, false, Board));
            Res.AddRange(Walk(x, y, 2, true, false, Board));

            return(Res.Distinct().ToList());
        }
コード例 #4
0
ファイル: Cards.cs プロジェクト: tjosgood/TurnSim
        public override List <PossibleMove> PossibleMoves(int x, int y, BoardClass Board)
        {
            var res = new List <PossibleMove>();

            res.Add(CheckPath(x, y, 1, 0, Board));
            res.Add(CheckPath(x, y, -1, 0, Board));
            res.Add(CheckPath(x, y, 0, 1, Board));
            res.Add(CheckPath(x, y, 0, -1, Board));
            return(res.Where(o => o != null).ToList());;
        }
コード例 #5
0
ファイル: Logic.cs プロジェクト: tjosgood/TurnSim
        public BoardClass MakeCopy()
        {
            var Copy = new BoardClass(TilesX, TilesY, Sim, Log, false);

            Copy.Tiles   = Tiles.Copy();
            Copy.Players = Players.Copy();
            Copy.Meeples = Meeples.Copy();
            Copy.ShadowLastPlayedCard = ShadowLastPlayedCard.Copy();

            Copy.OrthWalkPatterns = OrthWalkPatterns;
            Copy.DiagWalkPatterns = DiagWalkPatterns;


            return(Copy);
        }
コード例 #6
0
ファイル: Logic.cs プロジェクト: tjosgood/TurnSim
        public int Score(BoardClass Board)
        {
            int Score = 0;

            foreach (var c in Hand)
            {
                Score += c.ScoreValue;
            }
            foreach (var c in DiscardPile)
            {
                Score += c.ScoreValue;
            }
            foreach (var c in Board.GetOccupiedTiles(ID))
            {
                Score += c.ScoreValue;
            }
            return(Score);
        }
コード例 #7
0
ファイル: Logic.cs プロジェクト: tjosgood/TurnSim
        public NinjaGame(PictureBox RenderTarget = null, TextBox LogTarget = null, string LogFile = null, int UILogLevel = 0, int FileLogLevel = 0)
        {
            NumPlayers = 2;

            Log = new Logger(LogTarget, LogFile, UILogLevel, FileLogLevel);
            //Log = new Logger(LogTarget,_EnableUI:false);

            if (NumPlayers > 2)
            {
                Board = new BoardClass(8, 7, this, Log);
            }
            else
            {
                Board = new BoardClass(8, 6, this, Log);
            }

            RNG = new Random();
            Vis = new Visualiser(this, RenderTarget);
        }
コード例 #8
0
ファイル: Cards.cs プロジェクト: tjosgood/TurnSim
        private PossibleMove CheckPath(int x, int y, int xoff, int yoff, BoardClass Board)
        {
            int          xcur = x, ycur = y;
            PossibleMove LastGood = null;

            for (int steps = 0; steps < 100; steps++)
            {
                xcur += xoff;
                ycur += yoff;
                if (!Board.IsWalkable(xcur, ycur))
                {
                    break;
                }
                LastGood = new PossibleMove()
                {
                    FromX = x, FromY = y, ToX = xcur, ToY = ycur, ScoreValue = Board.Tiles[xcur, ycur].ScoreValue, Card = this, Destination = Board.Tiles[xcur, ycur]
                };
            }
            return(LastGood);
        }
コード例 #9
0
ファイル: Cards.cs プロジェクト: tjosgood/TurnSim
        private PossibleMove CheckPath(int x, int y, int xoff, int yoff, BoardClass Board)
        {
            int xcur = x, ycur = y;

            var Me = Board.GetMeepleAt(x, y);

            if (Me == null)
            {
                return(null);
            }

            for (int steps = 0; steps < 100; steps++)
            {
                xcur += xoff;
                ycur += yoff;
                if (!Board.IsWalkable(xcur, ycur, false))
                {
                    break;
                }

                var Enemy = Board.GetMeepleAt(xcur, ycur);

                if (Enemy != null)
                {
                    if (Enemy.Player.ID == Me.Player.ID)
                    {
                        break;
                    }
                    if (Board.IsWalkable(xcur + xoff, ycur + yoff))
                    {
                        return(new PossibleMove()
                        {
                            FromX = x, FromY = y, ToX = xcur, ToY = ycur, ScoreValue = Board.Tiles[xcur, ycur].ScoreValue, Card = this, Destination = Board.Tiles[xcur, ycur]
                        });
                    }
                }
            }
            return(null);
        }
コード例 #10
0
ファイル: Cards.cs プロジェクト: tjosgood/TurnSim
        public override List <PossibleMove> PossibleMoves(int x, int y, BoardClass Board, int PlayerID)
        {
            var res = new List <PossibleMove>();

            var Occupied = Board.GetOccupiedTiles(PlayerID).Select(o => o.Type).ToList();

            for (int i = 0; i < Board.TilesX; i++)
            {
                for (int j = 0; j < Board.TilesY; j++)
                {
                    if (Board.IsWalkable(i, j))
                    {
                        if (!Occupied.Contains(Board.Tiles[i, j].Type))
                        {
                            res.Add(new PossibleMove()
                            {
                                FromX = x, FromY = y, ToX = i, ToY = j, ScoreValue = Board.Tiles[i, j].ScoreValue, Card = this, Destination = Board.Tiles[i, j]
                            });
                        }
                    }
                }
            }

            if (Board.Players[PlayerID].AI)
            {
                var newres = new List <PossibleMove>();
                var Types  = res.Select(o => new { Move = o, Type = Board.Tiles[o.ToX, o.ToY].Type }).Where(o => o.Type != CardType.Trap).GroupBy(o => o.Type).Select(o => o.ToList()).ToList();

                foreach (var g in Types)
                {
                    g.Shuffle();
                    newres.AddRange(g.Take(3).Select(o => o.Move));
                }
                res = newres;
            }

            return(res);
        }
コード例 #11
0
ファイル: Cards.cs プロジェクト: tjosgood/TurnSim
        public List <PossibleMove> Walk(int x, int y, int steps, bool allowDiag, bool StealthScore, BoardClass Board)
        {
            var PossiblePaths = Board.GetWalkPattern(steps, allowDiag);
            var Result        = new List <PossibleMove>();

            foreach (var path in PossiblePaths)
            {
                int xcur = x, ycur = y;
                int sx = -1, sy = -1;
                var TotalScore = 0;
                var isValid    = true;

                foreach (var step in path)
                {
                    xcur += step.X;
                    ycur += step.Y;
                    if (StealthScore && sx == -1)
                    {
                        sx = xcur;
                        sy = ycur;
                    }
                    if (!Board.IsWalkable(xcur, ycur))
                    {
                        isValid = false;
                        break;
                    }
                    ;
                    TotalScore += Board.Tiles[xcur, ycur].ScoreValue;
                }

                if (isValid)
                {
                    Result.Add(new PossibleMove()
                    {
                        FromX = x, FromY = y, ToX = xcur, ToY = ycur, FirstX = sx, FirstY = sy, ScoreValue = StealthScore ? TotalScore : Board.Tiles[xcur, ycur].ScoreValue, Card = this, Destination = Board.Tiles[xcur, ycur]
                    });
                }
            }
            return(Result.Distinct().ToList());
        }
コード例 #12
0
ファイル: Cards.cs プロジェクト: tjosgood/TurnSim
 public virtual List <PossibleMove> PossibleMoves(int x, int y, BoardClass Board, int PlayerID)
 {
     return(PossibleMoves(x, y, Board));
 }
コード例 #13
0
ファイル: Cards.cs プロジェクト: tjosgood/TurnSim
 public virtual List <PossibleMove> PossibleMoves(int x, int y, BoardClass Board)
 {
     return(new List <PossibleMove>());
 }
コード例 #14
0
ファイル: Cards.cs プロジェクト: tjosgood/TurnSim
 public override List <PossibleMove> PossibleMoves(int x, int y, BoardClass Board)
 {
     return(Walk(x, y, 3, false, false, Board));
 }
コード例 #15
0
ファイル: Logic.cs プロジェクト: tjosgood/TurnSim
        public List <PossibleMove> AllPossibleMoves(Player p, BoardClass VirtualBoard = null)
        {
            Log.debug($"Enumerating moves for {p}");

            if (VirtualBoard == null)
            {
                VirtualBoard = Board;
                Log.debug($"Using current board data");
            }
            else
            {
                Log.debug($"Using VIRTUAL board data");
            }


            var AllMove = new List <PossibleMove>();

            var UsableCards = p.Hand.GroupBy(o => o.Type).Select(o => o.First());
            var Meeples     = VirtualBoard.Meeples.Where(o => o.Player.ID == p.ID);

            if (UsableCards.Select(o => o.Type).Contains(CardType.PlaceMeeple))
            {
                UsableCards = UsableCards.Where(o => o.Type == CardType.PlaceMeeple).ToList();
                Meeples     = Meeples.Where(o => o.X < 0).Take(1);
            }

            if (Log.Enabled)
            {
                Log.debug("useable cards:");
                foreach (var c in UsableCards)
                {
                    Log.debug(c.ToString());
                }
                Log.debug("useable meeples:");
                foreach (var c in Meeples)
                {
                    Log.debug(c.ToString());
                }
            }

            foreach (var C in UsableCards)
            {
                foreach (var M in Meeples)
                {
                    var Moves = C.PossibleMoves(M.X, M.Y, VirtualBoard, p.ID);
                    if (Log.Enabled)
                    {
                        Log.debug($"found {Moves.Count} moves for {M} using {C}");
                    }
                    AllMove.AddRange(Moves);
                }
            }

            if (p.AI)
            {
                foreach (var m in AllMove)
                {
                    if (m.Destination.Type == CardType.Stealth)
                    {
                        m.ScoreValue += 5;
                    }
                    // if (m.Destination.Type == CardType.Ambush) m.ScoreValue -= 1;
                }
            }

            Log.debug($"found total of {AllMove.Count} moves for {p}");

            return(AllMove);
        }