Ejemplo n.º 1
0
        private PraetorianPieceViewModel GetLastMovedPieceFromComputer(List<PraetorianPieceViewModel> computerMove, List<PraetorianPieceViewModel> previousBoard)
        {
            PraetorianPieceViewModel piece = new PraetorianPieceViewModel();
            foreach(var cPiece in computerMove)
            {
                if (cPiece.Piece != CellState.EMPTY && cPiece.Piece != CellState.PRAETORIAN)
                {
                    var pPiece = previousBoard.First(f => f.Piece == cPiece.Piece);
                    if (pPiece.Index != cPiece.Index)
                    {
                        piece = cPiece;
                        break;
                    }
                }
            }

            return piece;
        }
Ejemplo n.º 2
0
 public static Predicate<PraetorianPieceViewModel> findPiece(PraetorianPieceViewModel piece)
 {
     return delegate(PraetorianPieceViewModel find)
     {
         return find.Equals(piece);
     };
 }
Ejemplo n.º 3
0
        public JsonResult Interrogate(PraetorianPieceViewModel positionQuestioned)
        {
            if (positionQuestioned.IsAssassin)
            {
                var qPiece = _Board.Pieces.First(w => w.Position == positionQuestioned.Position);
                qPiece.IsCaught = true;
                _iMoveNumber++;
                _LastMove = new KeyValuePair<int, PraetorianPieceViewModel>(_iMoveNumber, new PraetorianPieceViewModel() { Piece = qPiece.Piece });
                _MasterMoveList.Add(new KeyValuePair<int, PraetorianPieceViewModel>(_iMoveNumber, qPiece));
                _Board.GameState = PraetorianGameState.PRAETORIANWIN;
            }
            else
            {
                var qPiece =_Board.Pieces.First(w => w.Position == positionQuestioned.Position);
                qPiece.HasBeenQuestioned = true;
                _iMoveNumber++;
                _LastMove = new KeyValuePair<int, PraetorianPieceViewModel>(_iMoveNumber, new PraetorianPieceViewModel() { Piece = qPiece.Piece, HasBeenQuestioned = true });
                _MasterMoveList.Add(new KeyValuePair<int, PraetorianPieceViewModel>(_iMoveNumber, qPiece));
                _Board.GameState = PraetorianGameState.ASSASSINTURN;
            }

            return Json(_Board);
        }
Ejemplo n.º 4
0
        public JsonResult Assassinate(PraetorianPieceViewModel positionKilled)
        {
            if (positionKilled.IsTarget == false)
                throw new Exception("Not a target... Something is wrong");

            var target = _Board.Pieces.FirstOrDefault(f => f.Index == positionKilled.Index && f.IsTarget);
            if(target != null)
            {
                int indexOfTarget = _Board.Pieces.ToList().FindIndex(findPiece(target));
                var newBoard = _Board.Pieces.ToList();
                
                newBoard[indexOfTarget].HasBeenQuestioned = false;
                newBoard[indexOfTarget].Index = indexOfTarget;
                newBoard[indexOfTarget].Position = _Board.Pieces.ToList()[indexOfTarget].Position;
                newBoard[indexOfTarget].IsAssassin = false;
                newBoard[indexOfTarget].IsDead = false;
                newBoard[indexOfTarget].IsTarget = false;
                newBoard[indexOfTarget].Piece = CellState.EMPTY;
                newBoard[indexOfTarget].IsCaught = false;
                newBoard[indexOfTarget].MovesMade = new List<KeyValuePair<int, int>>();

                _Board.Pieces = newBoard;
            }

            if (_Board.Pieces.Where(w => w.IsTarget).Count() > 0)
            {
                _Board.GameState = PraetorianGameState.PRAETORIANTURN;
            }
            else
            {
                _Board.GameState = PraetorianGameState.ASSASSINWIN;
            }
            
            return Json(_Board);
        }
Ejemplo n.º 5
0
        private void setPiece(int iRow, int iCol, int iStart, List<PraetorianPieceViewModel> pieces)
        {
            int iC = 0;
            Random ran = new Random();
            var peds = pieces.Where(w => w.Piece == CellState.EMPTY).Select(s => (int)s.Piece).ToList();


            int t = 0;
            int iIndex = 0;

            if (iRow == 7 && iCol == 7)
                iCol = 6;
            
            while (true)
            {
                System.Threading.Thread.Sleep(1);
                iC = ran.Next(iStart, iCol);

                iIndex = iRow * 8 + iC;
                if (pieces[iIndex].Piece == CellState.EMPTY)
                    break;
                
            }
            while (true)
            {
                t = ran.Next(0, ranList.Count() - 1);
                int iPedIndex = 0;

                if(pieces.Where(w => (int)w.Piece == ranList[t]).Count() == 0)
                {
                    iPedIndex = ranList[t];
                    ranList.RemoveAt(t);
                    pieces[iIndex] = new PraetorianPieceViewModel() { Piece = (CellState)Enum.Parse(typeof(CellState), iPedIndex.ToString()), Position = "sq_" + iIndex, Index = iIndex, MovesMade = new List<KeyValuePair<int, int>>() { new KeyValuePair<int, int>(0, iIndex) } };
                    break;
                }
            }
        }