Пример #1
0
 public void ConstructorTest()
 {
     var tmp = new Board ();
     Assert.AreEqual (6, tmp.NumberOfAnalogPins);
     Assert.AreEqual (20, tmp.NumberOfDigitalPins);
     Assert.AreEqual (5, tmp.AnalogReferenceVoltage);
 }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PrototypeBackend.BoardConfiguration"/> class.
        /// </summary>
        /// <param name="info">Info.</param>
        /// <param name="context">Context.</param>
        public BoardConfiguration(SerializationInfo info, StreamingContext context)
        {
            OnPinsUpdated = null;
            OnBoardUpdated = null;
            OnSequencesUpdated = null;
            OnSignalsUpdated = null;

            board = new Board ();
            Pins = new List<IPin> ();
            MeasurementCombinations = new List<MeasurementCombination> ();
            Sequences = new List<Sequence> ();

            board = (Board)info.GetValue ("Board", board.GetType ());
            Pins = (List<IPin>)info.GetValue ("Pins", Pins.GetType ());
            MeasurementCombinations = (List<MeasurementCombination>)info.GetValue ("MeasurementCombinations", MeasurementCombinations.GetType ());
            Sequences = (List<Sequence>)info.GetValue ("Sequences", Sequences.GetType ());
            ConfigSavePath = info.GetString ("ConfigSavePath");
            CSVSaveFolderPath = info.GetString ("CSVSaveFolderPath");
            UseMarker = info.GetBoolean ("UseMarker");
            LogRAWValues = info.GetBoolean ("LogRAWValues");

            Separator = info.GetString ("CSVSeparator");
            EmptyValueFilling = info.GetString ("EmptyValueFilling");
            UTCTimestamp = info.GetBoolean ("UTCTimestamp");
            LocalTimestamp = info.GetBoolean ("LocalTimestamp");
            TimeFormat = info.GetString ("TimeFormat");
            FileNameConvention = ((List<string>)info.GetValue ("FileNameConvention", new List<string> ().GetType ())).ToArray<string> ();
            FileNameTimeFormat = info.GetString ("FileNameTimeFormat");
            FileNameDateFormat = info.GetString ("FileNameDateFormat");
            ValueFormatCultur = info.GetString ("ValueFormatCultur");
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PrototypeBackend.BoardConfiguration"/> class.
 /// </summary>
 public BoardConfiguration()
 {
     board = new Board ();
     Pins = new List<IPin> ();
     MeasurementCombinations = new List<MeasurementCombination> ();
     Sequences = new List<Sequence> ();
     //just in case use the home directory of the user -> ensures write properties
     CSVSaveFolderPath = Environment.GetFolderPath (Environment.SpecialFolder.UserProfile);
 }
Пример #4
0
        public void UpdateBoard(Board board)
        {
            string mark = "";

            for (int x = 0; x < 8; x++)
            {
                for (int y = 0; y < 8; y++)
                {
                    if (!mark.Equals(""))
                    {
                        mark = ""; // Clear the mark
                    }

                    if (board.squares[x, y] != null)
                    {
                        if (board.squares[x, y].Color == TeamColor.WHITE) // Color forthe mark
                        {
                            mark += "W";
                        }
                        else
                        {
                            mark += "B";
                        }

                        switch (board.squares[x, y].GetType().ToString()) // Type of piece forthe mark
                        {
                            case "Backend.Pawn":
                                mark += "P";
                                break;
                            case "Backend.Rook":
                                mark += "R";
                                break;
                            case "Backend.Knight":
                                mark += "N";
                                break;
                            case "Backend.Bishop":
                                mark += "B";
                                break;
                            case "Backend.Queen":
                                mark += "Q";
                                break;
                            case "Backend.King":
                                mark += "K";
                                break;
                            default:
                                throw new ArgumentException();
                        }
                    }
                    squares[x, y].Content = mark;
                }
            }
        }
Пример #5
0
 public void Constructor2Test()
 {
     var tmp = new Board (42, 43) {
         Name = "TestBoard",
         MCU = "SuperModel",
         UseDTR = true
     };
     Assert.AreEqual (42, tmp.NumberOfAnalogPins);
     Assert.AreEqual (43, tmp.NumberOfDigitalPins);
     Assert.AreEqual ("TestBoard", tmp.Name);
     Assert.AreEqual ("SuperModel", tmp.MCU);
     Assert.AreEqual (true, tmp.UseDTR);
 }
Пример #6
0
        public Board(Board copy)
        {
            // Copy constructor
            // For use alongside Check()
            squares = new ChessPiece[8, 8];
            String temp;

            for(int x = 0; x < 8; x++)
            {
                for (int y = 0; y < 8; y++)
                {
                    if(copy.squares[x, y] != null)
                    {
                        temp = copy.squares[x, y].GetType().ToString();

                        switch(temp)
                        {
                            case "Backend.Pawn":
                                squares[x,y] = new Pawn(copy.squares[x,y].Color);
                                break;
                            case "Backend.Rook":
                                squares[x, y] = new Rook(copy.squares[x, y].Color);
                                break;
                            case "Backend.Knight":
                                squares[x, y] = new Knight(copy.squares[x, y].Color);
                                break;
                            case "Backend.Bishop":
                                squares[x, y] = new Bishop(copy.squares[x, y].Color);
                                break;
                            case "Backend.Queen":
                                squares[x, y] = new Queen(copy.squares[x, y].Color);
                                break;
                            case "Backend.King":
                                squares[x, y] = new King(copy.squares[x, y].Color);
                                break;
                            default:
                                throw new ArgumentException();
                        }
                    }
                }
            }
        }
Пример #7
0
        private Boolean CheckmateMovementCheck(int x, int y)
        {
            int[,] moves = GetValidKingMoves(x, y);
            Board temp;

            for(int i = 0; i < moves.GetLength(0); i++)
            {
                temp = new Board(this);
                temp.MovePiece(x, y, moves[i, 0], moves[i, 1]);

                if(!temp.Check(squares[x,y].Color)) // if it is possible to move the king out of check
                {
                    return false;
                }
            }
            return true;
        }
Пример #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PrototypeBackend.BoardSelectionArgs"/> class.
 /// </summary>
 /// <param name="board">Board.</param>
 /// <param name="aref">analog reference voltage.</param>
 /// <param name="arefname">analog reference voltage option.</param>
 public BoardSelectionArgs(Board board, double aref = 5, string arefname = "DEFAULT")
 {
     Board = board;
     AREF = aref;
     AREFName = arefname;
 }
Пример #9
0
 public MainWindow()
 {
     InitializeComponent();
     InitializeSquares();
     board = new Board();
 }
Пример #10
0
        // Handles movement
        private void moveLogic(int x, int y)
        {
            Board tempBoard;
            int[,] possibleMoves;

            tempBoard = new Board(board);
            possibleMoves = board.GetValidMoves(storedX, storedY);

            for (int i = 0; i < possibleMoves.GetLength(0); i++)
            {
                if (board.squares[storedX, storedY].GetType().ToString().Equals("Backend.King")) // Logic branch for Castling
                {
                    King tempKing = (King)board.squares[storedX, storedY];
                    Rook tempRook;

                    if (!tempKing.hasMoved && y == storedY && Math.Abs(x - storedX) == 2)
                    {
                        int rookIndex = 0;
                        int direction = -1;

                        if (x > storedX)
                        {
                            rookIndex = 7;
                            direction = 1;
                        }

                        if (board.squares[rookIndex, y].GetType().ToString().Equals("Backend.Rook"))
                        {
                            tempRook = (Rook)board.squares[rookIndex, y];
                            if (!tempRook.hasMoved)
                            {
                                if (direction == -1 &&             // Scan for pieces blocking the way in the proper direction
                                    board.squares[y, 1] == null &&
                                    board.squares[y, 2] == null &&
                                    board.squares[y, 3] == null ||
                                    direction == 1 &&
                                    board.squares[y, 5] == null &&
                                    board.squares[y, 6] == null)
                                {
                                    if (!tempBoard.Check(board.squares[storedX, storedY].Color)) // The next 3 IF statements are for the rules that you cannot castle into, out of, or through check
                                    {
                                        tempBoard.MovePiece(storedX, y, storedX + direction, y);

                                        if (!tempBoard.Check(board.squares[storedX + direction, storedY].Color))
                                        {
                                            tempBoard.MovePiece(storedX, y, storedX + (direction * 2), y);

                                            if (!tempBoard.Check(board.squares[storedX + (direction * 2), storedY].Color))
                                            {
                                                board.MovePiece(storedX, storedY, x, y);                           // Congratulations, sucessful castle
                                                board.MovePiece(rookIndex, storedY, storedX + direction, storedY);
                                                storedX = -1;
                                                storedY = -1;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else if (possibleMoves[i, 0] == x && possibleMoves[i, 1] == y)
                {
                    tempBoard.MovePiece(storedX, storedY, x, y);
                    if (!tempBoard.Check(tempBoard.squares[x, y].Color))
                    {
                        board.MovePiece(storedX, storedY, x, y);
                        UpdateBoard(board);

                        if(board.squares[x,y].GetType().ToString().Equals("Backend.King"))
                        {
                            King tempKing = (King)board.squares[x, y];
                            tempKing.hasMoved = true;
                        }
                        if (board.squares[x, y].GetType().ToString().Equals("Backend.Rook"))
                        {
                            Rook tempRook = (Rook)board.squares[x, y];
                            tempRook.hasMoved = true;
                        }

                        if (currentColor == TeamColor.WHITE)
                        {
                            if (board.Check(TeamColor.BLACK) && board.Checkmate(TeamColor.BLACK))
                            {
                                MessageBox.Show("WHITE wins!");
                                Environment.Exit(0); // Enviroment.Exit closes the program. Game ends at checkmate, right?
                            }
                            currentColor = TeamColor.BLACK;

                        }
                        else
                        {
                            if (board.Check(TeamColor.WHITE) && board.Checkmate(TeamColor.BLACK))
                            {
                                MessageBox.Show("BLACK wins!");
                                Environment.Exit(0);
                            }
                            currentColor = TeamColor.WHITE;
                        }

                        this.Title = currentColor.ToString() + " Turn!";
                    }
                    break;
                }

                tempBoard.DestroyBoard();
                storedX = -1;
                storedY = -1;
            }
        }
Пример #11
0
        public void RAWToVoltTest()
        {
            var b = new Board ();

            Assert.AreEqual (5, b.AnalogReferenceVoltage);
            Assert.AreEqual ("DEFAULT", b.AnalogReferenceVoltageType);

            Assert.AreEqual (5, b.RAWToVolt (1023));
            Assert.AreEqual (2.5, b.RAWToVolt (511.5));

            b.AnalogReferenceVoltage = 3;
            Assert.AreEqual (1.5, b.RAWToVolt (511.5));
        }
Пример #12
0
		public static void Main(string[] args)
		{
			Console.WriteLine ("Game Start");
			Board GameBoard = new Board ();
			GameBoard.beginGameplay ();
		}
Пример #13
0
		/// <summary>
		/// Init the arduinocontroller.
		/// </summary>
		/// <param name="apins">Number of analog pins</param>
		/// <param name="dpins">Number of digital pins</param>
		public static void Init (uint apins = 6, uint dpins = 20)
		{
			_board = new Board ();
			NumberOfAnalogPins = apins;
			NumberOfDigitalPins = dpins;

			OnConnectionChanged += (sender, e) =>
			{
				if (e.Connected)
				{
					GetModel ();
					GetNumberAnalogPins ();
					GetNumberDigitalPins ();
					GetAnalogPinNumbers ();
					GetSDASCL ();
				}
			};

			SerialPortName = "";
			#if FAKESERIAL
			IsConnected = true;
			#else
			isConnected = false;
			#endif

			AutoConnectTimer = new System.Threading.Thread (() =>
			{
				while (!IsConnected)
				{
					foreach (string s in System.IO.Ports.SerialPort.GetPortNames())
					{
						Console.WriteLine ("attemting auto connect to " + s);
						SerialPortName = s;

						Setup (false);
						System.Threading.Thread.Sleep (200);
						if (IsConnected)
							break;
						Disconnect ();
						Setup (true);
						System.Threading.Thread.Sleep (200);
						if (IsConnected)
							break;
						Disconnect ();
					}
				}
			});
			if (AutoConnect)
			{
				AutoConnectTimer.Start ();
			}
		}