Esempio n. 1
0
        public void UiMethods()
        {
            Ui o = new Ui(new Game("compact", null));

            Assert.Equal("White", o.Turn(true));
            Assert.Equal("Black", o.Turn(false));

            Assert.Equal("Queen", o.At('d', '8'));
            Assert.Equal("King", o.At('e', '1'));
            Assert.Equal("Pawn", o.At('g', '7'));
        }
Esempio n. 2
0
        Draw(Ui ui, string unused)
        {
            Ui.Pin(this.X, this.Y);
            string name;

            foreach (JsonElement swap in Helper.JsonToStateList(ui.State, "Reach"))
            {
                var x     = swap[0].GetInt32();
                var y     = swap[1].GetInt32();
                var xSwap = swap[2].GetInt32();
                var ySwap = swap[3].GetInt32();
                var sym   = ui.At(xSwap, ySwap);
                if (sym == "p")
                {
                    // pawn case disambiguation
                    sym = "o";
                }

                // empty
                name = " . ";
                // capture
                if (xSwap > 0 && ySwap > 0)
                {
                    name = "(" + sym + ")";
                }

                if (ui.UiState.Chosen)
                {
                    // empty
                    name = " * ";
                    // capture
                    if (xSwap > 0 && ySwap > 0)
                    {
                        name = "{" + sym + "}";
                    }
                }

                var piece = Helper.JsonToSelection(ui.State);

                // castle
                if (!Helper.JsonIsNull(ui.State, "Selection") &&
                    piece[0].GetString().ToUpper() == "K" && xSwap > 0 && x != xSwap)
                {
                    name = " % ";
                }

                // en passant
                string more = null;
                if (!Helper.JsonIsNull(ui.State, "Selection") &&
                    piece[0].GetString().ToUpper() == "P" && ySwap > 0 && y != ySwap)
                {
                    Ui.Pin(0, 28);
                    Ui.Write($"{piece[0].GetString()} {piece[2].GetInt32()} {piece[3].GetInt32()}");
                    name = " . ";
                    if (ui.UiState.Chosen)
                    {
                        name = " * ";
                        more = "(" + sym + ")";
                    }
                }

                if (this.Style == "compact" && xSwap == 0 && ySwap == 0)
                {
                    Ui.Pin(this.X + x - 2, this.Y + 8 - y);
                    Ui.Write(name);
                }
                else if (this.Style == "wide")
                {
                    Ui.Pin(this.X + 4 * x - 5, this.Y + 17 - 2 * y);
                    Ui.Write(name);
                    if (more != null)
                    {
                        Ui.Pin(this.X + 4 * x - 5, this.Y + 19 - 2 * y);
                        if (char.IsLower(piece[0].GetString()[0]))
                        {
                            Ui.Pin(this.X + 4 * x - 5, this.Y + 15 - 2 * y);
                        }
                        Ui.Write(more);
                    }
                }
            }
        }