Exemplo n.º 1
0
        private void newGameToolStripMenuItem_Click(object sender, EventArgs e)
        {
            engine = new KaroEngineWrapper();

            pictureBox1.Invalidate();

            btnDoMove.Enabled = true;
            btn.Enabled       = true;
        }
Exemplo n.º 2
0
        // Generate random move(s)
        private void button1_Click(object sender, EventArgs e)
        {
            engine = new KaroEngineWrapper();
            UpdateGUI();

            engine.InsertByXY(5, 4);
            engine.InsertByXY(6, 4);
            engine.InsertByXY(7, 4);
            engine.InsertByXY(8, 4);
            engine.InsertByXY(9, 4);

            engine.InsertByXY(5, 5);
            engine.InsertByXY(6, 5);
            engine.InsertByXY(7, 5);
            engine.InsertByXY(8, 5);
            engine.InsertByXY(9, 5);

            engine.InsertByXY(5, 6);
            engine.InsertByXY(6, 6);

            Application.DoEvents();

            int times = int.Parse(textBox1.Text);
            int moves = 0;

            DateTime startTijd = DateTime.Now;
            TimeSpan timeDiff  = DateTime.Now - DateTime.Now;

            for (int i = 0; i < times; i++)
            {
                engine.CalculateComputerMove();
                moves++;
                UpdateGUI();
                Application.DoEvents();

                if (engine.GetGameState() == GameState.GAMEFINISHED)
                {
                    timeDiff = DateTime.Now - startTijd;
                    ShowWinning(moves, (float)timeDiff.TotalSeconds, false);
                    break;
                }
            }

            timeDiff = DateTime.Now - startTijd;

            this.txtMessageLog.Text = "Moves:\t" + moves + "\r\n\r\n" + this.txtMessageLog.Text;
            this.txtMessageLog.Text = "Avarage:\t" + (timeDiff.TotalSeconds / times) + " Seconds \r\n" + this.txtMessageLog.Text;
            this.txtMessageLog.Text = "Total:\t" + timeDiff.TotalSeconds + " Seconds \r\n" + this.txtMessageLog.Text;
        }
Exemplo n.º 3
0
        // Debug options

        public Form1()
        {
            engine     = new KaroEngineWrapper();
            penBlack   = new Pen(Color.Black, 1);
            penGray    = new Pen(Color.Gray, 2);
            penGreen   = new Pen(Color.Green, 2);
            brushBlack = Brushes.Black;
            brushRed   = Brushes.Red;
            brushWhite = Brushes.White;
            brushBlue  = Brushes.Blue;

            clickedFirst  = new Point(-1, -1);
            clickedSecond = new Point(-1, -1);
            clickedTile   = new Point(-1, -1);
            possibleMoves = null;

            InitializeComponent();
            textBox1.Text = "5";
            textBox2.Text = "1";
            UpdateGUI();
        }
Exemplo n.º 4
0
        private void button2_Click(object sender, EventArgs e)
        {
            engine = new KaroEngineWrapper();
            UpdateGUI();

            DateTime startTijd = DateTime.Now;
            TimeSpan timeDiff  = DateTime.Now - DateTime.Now;

            int white = 0;
            int red   = 0;
            int draw  = 0;

            bool bdraw = false;

            int games = int.Parse(textBox2.Text);

            for (int i = 0; i < games; i++)
            {
                newGameToolStripMenuItem_Click(sender, e);
                int moves = 0;
                startTijd = DateTime.Now;

                while (engine.GetGameState() != GameState.GAMEFINISHED)
                {
                    if (moves >= 180)
                    {
                        bdraw = true;
                        break;
                    }

                    engine.CalculateComputerMove();
                    moves++;
                    UpdateGUI();
                    Application.DoEvents();
                }


                textBox2.Text = "" + (int.Parse(textBox2.Text) - 1);

                if (bdraw)
                {
                    draw++;
                }
                else
                {
                    if (engine.GetTurn() == Player.WHITE)
                    {
                        red++;
                    }
                    if (engine.GetTurn() == Player.RED)
                    {
                        white++;
                    }
                }
                bdraw = false;

                timeDiff = DateTime.Now - startTijd;
                ShowWinning(moves, (float)timeDiff.TotalSeconds, bdraw);
            }

            this.txtMessageLog.Text = "Draw\t" + draw + "\r\n\r\n" + this.txtMessageLog.Text;
            this.txtMessageLog.Text = "RED:\t" + red + "\r\n" + this.txtMessageLog.Text;
            this.txtMessageLog.Text = "WHITE:\t" + white + " \r\n" + this.txtMessageLog.Text;
            this.txtMessageLog.Text = "Played:\t" + games + "\r\n" + this.txtMessageLog.Text;

            textBox2.Text = "" + games;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Starts a new game
        /// </summary>
        public void NewGame()
        {
            engine                     = new KaroEngineWrapper();
            this.selectedPiece         = 0;
            this.selectedTile          = 0;
            this.selectedStartingPiece = -1;
            computerIsThinking         = false;
            undoTimer                  = 0;
            moveUndone                 = false;
            startUndoTimer             = false;
            didLastMove                = false;

            // clear tiles
            foreach (var tile in TileComponents)
            {
                Components.Remove(tile.Value);
            }
            TileComponents.Clear();

            // clear pieces
            foreach (var piece in PieceComponents)
            {
                Components.Remove(piece.Value);
            }
            PieceComponents.Clear();

            // add the tiles
            for (int x = 0; x < BOARDWIDTH; x++)
            {
                for (int y = 0; y < BOARDWIDTH; y++)
                {
                    KaroEngine.Tile tile = engine.GetByXY(x, y);
                    if (tile != KaroEngine.Tile.BORDER && tile != KaroEngine.Tile.EMPTY)
                    {
                        Tile t = new Tile(this, tileModel, false, new Point(x, y));
                        this.TileComponents.Add(y * BOARDWIDTH + x, t);
                        Components.Add(t);
                    }
                }
            }
            StartingPieces.Clear();

            //White pawns
            for (int i = 0; i < 3; i += 1)
            {
                Tile t = new Tile(this, tileModel, false, new Point(i + 7, 3));
                t.TileMatrix *= Matrix.CreateTranslation(0f, -1f, 0f);
                Piece p = new Piece(this, pieceModel, true, t, Color.White.ToVector3());
                this.StartingPieces.Add(p);
                this.Components.Add(p);
                t             = new Tile(this, tileModel, false, new Point(i + 7, 4));
                t.TileMatrix *= Matrix.CreateTranslation(0f, -1f, 0f);
                p             = new Piece(this, pieceModel, true, t, Color.White.ToVector3());
                this.StartingPieces.Add(p);
                this.Components.Add(p);
            }

            //Red pawns
            for (int i = 0; i < 3; i += 1)
            {
                Tile t = new Tile(this, tileModel, false, new Point(i + 7, 9));
                t.TileMatrix *= Matrix.CreateTranslation(0f, -1f, 0f);
                Piece p = new Piece(this, pieceModel, true, t, Color.Tomato.ToVector3());
                this.StartingPieces.Add(p);
                this.Components.Add(p);
                t             = new Tile(this, tileModel, false, new Point(i + 7, 10));
                t.TileMatrix *= Matrix.CreateTranslation(0f, -1f, 0f);
                p             = new Piece(this, pieceModel, true, t, Color.Tomato.ToVector3());
                this.StartingPieces.Add(p);
                this.Components.Add(p);
            }
        }