Esempio n. 1
0
    private static void DownloadImageFile(string url, string folder)
    {
        Console.Write("folder " + Prints.Arrow());
        folder = Console.ReadLine();

        Downloader.DownloadImage(url, folder);
    }
Esempio n. 2
0
 /**
  * #function SingleBot::SingleBot |
  * @author JavaComSci |
  * @desc Creates a new board for the bot.  |
  * @header SingleBot() |
  * @param void : SingleBot takes no params |
  * @returns SingleBot : An object of single bot class |
  */
 public SingleBot()
 {
     // create a board for this bot
     // Console.WriteLine("I AM A SINGLE BOT");
     shapeColor     = 1;
     botInfoPrinter = new Prints();
 }
Esempio n. 3
0
    public static void SelectFileFormat(string url)
    {
userChoice:

        Prints.DownloadMenu();
        string userInput = Console.ReadLine();

        string folder = null;

        if (IsValidDownloadOption(userInput))
        {
            if (userInput == Strings.DOWNLOAD_VIDEO_AUDIO)
            {
                DownloadMP4MP3File(url, folder);
            }
            if (userInput == Strings.DOWNLOAD_IMAGE)
            {
                DownloadImageFile(url, folder);
            }
        }
        else
        {
            Console.WriteLine("Invalid download option.");
            goto userChoice;
        }
    }
Esempio n. 4
0
 public static void DownloadMenu()
 {
     Console.ForegroundColor = ConsoleColor.DarkMagenta;
     Console.WriteLine("Select what you want to download:");
     Console.ResetColor();
     Console.WriteLine("1 - Video/Audio");
     Console.WriteLine("2 - Image");
     Console.Write(Prints.Arrow());
 }
Esempio n. 5
0
 public static void CreateFile(string path)
 {
     // Create directory for store default user path (If it doesn't exists, no problem).
     Directory.CreateDirectory(defaultUserPath);
     // First, clean all the .txt content.
     File.WriteAllText(defaultUserPath + @"\DefaultPath.txt", Prints.Blank());
     // After that, add the user path.
     File.AppendAllText(defaultUserPath + @"\DefaultPath.txt", path);
 }
Esempio n. 6
0
    public void shiftRows(Lobby lobby, bool bottomColumnFilled)
    {
        int[,] board = lobby.game.board.board;
        Prints prints = new Prints();

        Console.WriteLine("APPLIED BOARD");
        prints.PrintMultiDimArr(lobby.game.board.board);
        int rows = board.GetLength(0);
        int cols = board.GetLength(1);
        // shift code
        List <int[]> SquaresList = new List <int[]>();

        for (int j = 0; j < cols; j++)
        {
            int shiftAmount = (board[rows - 1, j] == 0) ? 1 : 0;
            for (int i = board.GetLength(0) - 2; i >= 0; i--)
            {
                if (board[i, j] > 0)
                {
                    int[] temp = { i, j, shiftAmount };
                    SquaresList.Add(temp);
                }
                else
                {
                    shiftAmount++;
                }
            }
        }

        if (!bottomColumnFilled)
        {
            for (int j = 0; j < cols; j++)
            {
                if (board[rows - 1, j] != 0)
                {
                    int[] temp = { rows - 1, j, 0 };
                    SquaresList.Add(temp);
                }
            }
        }

        int[,] newBoard = new int[board.GetLength(0), board.GetLength(1)];

        for (int a = 0; a < SquaresList.Count; a++)
        {
            int[] temp = SquaresList[a];
            newBoard[temp[0] + temp[2], temp[1]] = board[temp[0], temp[1]];
        }
        Console.WriteLine("NEW BOARDTM");
        prints.PrintMultiDimArr(newBoard);
        lobby.game.board.board = newBoard;
        Console.WriteLine("SHIFTED BOARD");
        prints.PrintMultiDimArr(lobby.game.board.board);
    }
Esempio n. 7
0
        public void SpecificShiftSituation()
        {
            lobbyManager.createLobby(4, "bob", 5, "no", (WebSocketSharp.WebSocket)null);
            Lobby lobby = new Lobby("1", 0);

            lobby.game             = new GameState(10, 10);
            lobby.game.board.board = new int[, ] {
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 1, 1, 3, 0, 0, 0, 0, 0, 0 },
                { 0, 1, 1, 1, 1, 0, 0, 0, 0, 0 },
                { 1, 1, 1, 2, 3, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
            };
            lobbyManager.shiftRows(lobby, true);
            int[,] resBoard  = lobby.game.board.board;
            int[,] testBoard = new int[, ] {
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 1, 1, 3, 0, 0, 0, 0, 0, 0 },
                { 0, 1, 1, 1, 1, 0, 0, 0, 0, 0 },
                { 1, 1, 1, 2, 3, 0, 0, 0, 0, 0 }
            };
            bool isSameBoard = true;

            for (int i = 0; i < testBoard.GetLength(0); i++)
            {
                for (int j = 0; j < testBoard.GetLength(1); j++)
                {
                    if (resBoard[i, j] != testBoard[i, j])
                    {
                        isSameBoard = false;
                    }
                }
            }
            Prints prints = new Prints();

            Console.WriteLine("RESULTING BOARD");
            prints.PrintMultiDimArr(lobby.game.board.board);
            Assert.That(isSameBoard, Is.EqualTo(true));
        }
Esempio n. 8
0
        public void RemovePowerCubeSecondRowColumn()
        {
            lobbyManager.createLobby(4, "bob", 5, "no", (WebSocketSharp.WebSocket)null);
            Lobby lobby = new Lobby("1", 0);

            lobby.game             = new GameState(8, 8);
            lobby.game.board.board = new int[, ] {
                { 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 1, 0, 0, 0, 0, 0, 0 },
                { 0, 1, 0, 0, 0, 0, 0, 0 },
                { 0, 1, 0, 0, 0, 0, 0, 0 },
                { 0, 1, 0, 0, 0, 0, 0, 0 },
                { 0, 1, 0, 0, 0, 0, 0, 0 },
                { 1, 2, 1, 1, 1, 1, 1, 1 },
                { 1, 1, 1, 1, 0, 1, 1, 1 }
            };
            lobbyManager.checkRows(lobby);
            int[,] resBoard  = lobby.game.board.board;
            int[,] testBoard = new int[, ] {
                { 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0 },
                { 1, 0, 1, 1, 0, 1, 1, 1 }
            };
            bool isSameBoard = true;

            for (int i = 0; i < testBoard.GetLength(0); i++)
            {
                for (int j = 0; j < testBoard.GetLength(1); j++)
                {
                    if (resBoard[i, j] != testBoard[i, j])
                    {
                        isSameBoard = false;
                    }
                }
            }
            Prints prints = new Prints();

            Console.WriteLine("RESULTING BOARD");
            prints.PrintMultiDimArr(lobby.game.board.board);
            Assert.That(isSameBoard, Is.EqualTo(true));
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine(Prints.Blank());

                Console.WriteLine(Prints.WelcomeMessage());
                Console.WriteLine(Prints.WelcomeMessageHelp());

                Console.WriteLine(Prints.Blank());

                Console.Write(Prints.Arrow());

                string userInput = Console.ReadLine();
                UserCommands.ReturnUserCommandInformation(userInput);
            }
        }
Esempio n. 10
0
    public static void HelpManual()
    {
        string manualTitle = "                      Here is your 'help' manual!";
        string download    = "   {https://youtube/url}      -------    for start download.";
        string url         = "      1 - Video/Audio         -------    select for download video and audio.";
        string type        = "      2 - Image               -------    select for download an image.";
        string folder      = "      folder                  -------    the folder path.";

        string setPath = "     --set-path               -------    for start a new default folder path location.";
        string path    = "        path                  -------    the name of the default path.";

        string hint = "        hint                  -------    use '.' for use default properties.";

        Console.ForegroundColor = ConsoleColor.DarkMagenta;
        Console.WriteLine(manualTitle);
        Console.ResetColor();

        Console.ForegroundColor = ConsoleColor.Red;
        Console.WriteLine(download);
        Console.ResetColor();

        Console.ForegroundColor = ConsoleColor.Green;

        Console.WriteLine(url);
        Console.WriteLine(type);
        Console.WriteLine(folder);

        Console.ResetColor();

        Console.ForegroundColor = ConsoleColor.Red;
        Console.WriteLine(setPath);
        Console.ResetColor();

        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine(path);
        Console.ResetColor();

        Console.WriteLine(Prints.Blank());

        Console.ForegroundColor = ConsoleColor.DarkYellow;
        Console.WriteLine(hint);
        Console.ResetColor();
    }
Esempio n. 11
0
    public static void SetURLPath()
    {
userChoice:

        Console.WriteLine(Prints.Blank());

        Console.Write(Strings.PATH + " " + Prints.Arrow());
        string path = Console.ReadLine();

        if (!Validator.IsValidDefaultPathRequest(path))
        {
            Prints.InvalidDefaultPath();

            goto userChoice;
        }

        DefaultFolder.CreateFile(path);

        Prints.Done();
    }
Esempio n. 12
0
 public DoubleBot()
 {
     // create a board for this bot
     Console.WriteLine("I AM A DOUBLE BOT");
     botInfoPrinter = new Prints();
 }
Esempio n. 13
0
    public int[][] GenerateRandomPiece()
    {
        Prints botInfoPrinter = new Prints();

        int[][] piece = new int[][] {
            new int[] { 0, 0, 0, 0 },
            new int[] { 0, 0, 0, 0 },
            new int[] { 0, 0, 0, 0 },
            new int[] { 0, 0, 0, 0 },
        };
        int[] gen = { 2, 2, 2, 3, 3, 3, 4, 4, 5, 5 };

        Random random     = new Random();
        int    startIndex = random.Next(0, gen.Length);
        // Console.WriteLine("THE INDEX IS " + startIndex);
        int count = gen[startIndex];
        // Console.WriteLine("COUNT IS " + count);

        int i = random.Next(0, 4);
        int j = random.Next(0, 4);

        piece[i][j] = 1;

        count = count - 1;

        Dictionary <string, Tuple <int, int, int> > values = new Dictionary <string, Tuple <int, int, int> >();

        while (count > 0)
        {
            values["left"]  = new Tuple <int, int, int>(GetSquarePriority(i, j - 1, piece), i, j - 1);
            values["right"] = new Tuple <int, int, int>(GetSquarePriority(i, j + 1, piece), i, j + 1);
            values["up"]    = new Tuple <int, int, int>(GetSquarePriority(i - 1, j, piece), i - 1, j);
            values["down"]  = new Tuple <int, int, int>(GetSquarePriority(i + 1, j, piece), i + 1, j);
            var maxVal = -1;
            Tuple <int, int, int> bestVal = null;
            foreach (string v in values.Keys)
            {
                if (maxVal == -1)
                {
                    maxVal  = values[v].Item1;
                    bestVal = values[v];
                }
                if (values[v].Item1 >= maxVal)
                {
                    // Console.WriteLine("HERE " + maxVal + " " + values[v].Item2);
                    maxVal  = values[v].Item1;
                    bestVal = values[v];
                }
            }
            if (maxVal == 1)
            {
                // Console.WriteLine("MAX VAL " + maxVal);
                piece[bestVal.Item2][bestVal.Item3] = 1;
                count = count - 1;
            }
            else
            {
                break;
            }
        }
        // Console.WriteLine("PIECE ");
        // botInfoPrinter.PrintJaggedArr(piece);
        return(piece);
    }
Esempio n. 14
0
        static void Main(string[] args)
        {
            // // initialize game state
            GameState game = new GameState(6, 8);

            game.players = new Dictionary <int, Player>();
            Dictionary <string, Lobby> lobbies = new Dictionary <string, Lobby>();

            // // printing
            Prints infoPrinter = new Prints();

            // // CHANGE - RECIEVED FROM THE FRONTEND - REPLACEMENT
            int numBots = 1;

            switch (numBots)
            {
            case 1:
                game.bot = new SingleBot();
                break;

            case 2:
                game.bot = new DoubleBot();
                break;

            case 3:
                game.bot = new TripleBot();
                break;

            default:
                game.bot = null;
                break;
            }


            List <Block> bot1Blocks  = new List <Block>();
            List <Block> bot2Blocks  = new List <Block>();
            List <Block> bot3Blocks  = new List <Block>();
            RandomPiece  randomPiece = new RandomPiece();

            // game.board.board =  new int[,]{
            //     {0, 0, 0, 0, 0, 0},
            //     {0, 0, 0, 0, 0, 0},
            //     {0, 0, 0, 0, 0, 0},
            //     {0, 0, 0, 0, 0, 1},
            //     {0, 0, 0, 1, 1, 1},
            //     {1, 0, 1, 1, 1, 1}
            // };

            // game.board.board = new int[,]{
            //     {0, 0, 0, 0, 0, 0, 0},
            //     {0, 0, 0, 0, 0, 0, 0},
            //     {0, 0, 0, 0, 0, 0, 0},
            //     {0, 0, 0, 0, 0, 1, 1},
            //     {0, 0, 0, 1, 0, 1, 1},
            //     {1, 0, 1, 1, 1, 1, 1},
            // };
            game.board.board = new int[, ] {
                { 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 1, 1, 0 },
                { 0, 0, 0, 1, 0, 1, 1, 0 },
                { 0, 0, 0, 1, 1, 1, 1, 1 },
            };
            int[][] block11 = new int[][] {
                new int[] { 0, 0, 0, 0 },
                new int[] { 0, 1, 1, 0 },
                new int[] { 0, 1, 0, 0 },
                new int[] { 0, 0, 0, 0 },
            };
            int[][] block21 = new int[][] {
                new int[] { 0, 0, 0, 0 },
                new int[] { 0, 1, 0, 0 },
                new int[] { 1, 1, 0, 0 },
                new int[] { 0, 1, 0, 0 },
            };
            int[][] block31 = new int[][] {
                new int[] { 0, 0, 0, 0 },
                new int[] { 0, 1, 0, 0 },
                new int[] { 0, 1, 0, 0 },
                new int[] { 0, 1, 0, 0 },
            };
            // int[][] block11 = randomPiece.GenerateRandomPiece();
            // int[][] block21 = randomPiece.GenerateRandomPiece();
            // int[][] block31 = randomPiece.GenerateRandomPiece();
            // bot1Blocks.Add(new Block(block11, 1));
            // bot2Blocks.Add(new Block(block21, 1));
            // bot3Blocks.Add(new Block(block31, 1));
            // List<List<Block>> blocks = new List<List<Block>>();
            // blocks.Add(bot1Blocks);
            // blocks.Add(bot2Blocks);
            // blocks.Add(bot3Blocks);

            // game.bot.GetMove(game.board, blocks);
            // try {
            //     game.bot.GetMove(game.board, blocks);
            // } catch (Exception e) {
            //     Console.WriteLine("Recieved error: "  + e.Message);
            // }

            // connection and adding to the db scores
            // List<string> players = new List<string>();
            // players.Add("modified");
            // players.Add("hi");
            // players.Add(null);
            // players.Add(null);
            // ScoresInfo scoresInfo = new ScoresInfo("Team HIHIOWE", players, 1, 6000);
            // SQLConnection.AddTeamScore(scoresInfo);
            // Tuple<List<ScoresInfo>, ScoresInfo> retrievedInfo = SQLConnection.GetTopTeamsAndCurrentTeam("Team HIHIOWE");
            // Console.WriteLine("Top teams");
            // infoPrinter.PrintScoreList(retrievedInfo.Item1);
            // Console.WriteLine("Current team");
            // infoPrinter.PrintScoreInfo(retrievedInfo.Item2);


            // List<ScoresInfo> retrieved = SQLConnection.GetTopTeams();
            // infoPrinter.PrintScoreList(retrieved);


            // string teamName = "Team10";
            // int score = 100;
            // string scoreInfo = "Best achieving score: " + score;

            // PointF firstLocation = new PointF(120f, 200f);
            // PointF secondLocation = new PointF(120f, 240f);

            // Bitmap bitmap = new System.Drawing.Bitmap("canvas.png");
            // string imageFilePath = "canvas.bmp";

            // using(Graphics graphics = Graphics.FromImage(bitmap))
            // {
            //     using (Font arialFont =  new Font("Arial", 20))
            //     {
            //         graphics.DrawString(teamName, arialFont, Brushes.Red, firstLocation);
            //         int i = teamName.Length;
            //         while(i < scoreInfo.Length - 2) {
            //             graphics.DrawString(".", arialFont, Brushes.Red, new PointF((120 + teamName.Length * 8) + (10 * i), 200f));
            //             i++;
            //         }
            //         graphics.DrawString(scoreInfo, arialFont, Brushes.Blue, secondLocation);
            //     }
            // }

            // string outputFileName =imageFilePath;
            // using (MemoryStream memory = new MemoryStream())
            // {
            //     using (FileStream fs = new FileStream(outputFileName, FileMode.Create, FileAccess.ReadWrite))
            //     {
            //         bitmap.Save(memory, ImageFormat.Jpeg);
            //         byte[] bytes = memory.ToArray();
            //         fs.Write(bytes, 0, bytes.Length);
            //     }
            // }


            // string teamName = "AHHHH";
            // int score = 50;
            // string scoreInfo = "Best achieving score: " + score;

            // PointF firstLocation = new PointF(320f, 400f);
            // PointF secondLocation = new PointF(320f, 490f);

            // Bitmap b = null;
            // Bitmap bitmap;
            // if(b == null) {
            //     bitmap = new System.Drawing.Bitmap("canvas.png");
            // } else {
            //     bitmap = b;
            // }


            // using(Graphics graphics = Graphics.FromImage(bitmap))
            // {
            //     using (Font arialFont =  new Font("Arial", 50))
            //     {
            //         graphics.DrawString(teamName, arialFont, Brushes.Red, firstLocation);
            //         int i = teamName.Length;
            //         graphics.DrawString(scoreInfo, arialFont, Brushes.Blue, secondLocation);
            //     }
            // }

            // string imageFilePath = "canvas.bmp";
            // string outputFileName = imageFilePath;
            // using (MemoryStream memory = new MemoryStream())
            // {
            //     using (FileStream fs = new FileStream(outputFileName, FileMode.Create, FileAccess.ReadWrite))
            //     {
            //         bitmap.Save(memory, ImageFormat.Jpeg);
            //         byte[] bytes = memory.ToArray();
            //         fs.Write(bytes, 0, bytes.Length);
            //     }
            // }


            // Bitmap bImage = bitmap;
            // System.IO.MemoryStream ms = new MemoryStream();
            // bImage.Save(ms, ImageFormat.Jpeg);
            // byte[] byteImage = ms.ToArray();
            // var encodedImage= Convert.ToBase64String(byteImage);
            // Console.WriteLine("ENCODED IMAGE " +  encodedImage);


            // create localhost web socket server on port 5202
            var wssv = new WebSocketServer("ws://0.0.0.0:5202");

            wssv.Start();
            wssv.AddWebSocketService <LobbyManager>("/lobby", () => new LobbyManager(lobbies));
            wssv.AddWebSocketService <Play>("/play", () => new Play(lobbies));
            wssv.AddWebSocketService <ScoresManager>("/scores", () => new ScoresManager());
            wssv.AddWebSocketService <ShareManager>("/share", () => new ShareManager());
            wssv.AddWebSocketService <LegendManager>("/legend", () => new LegendManager());
            wssv.AddWebSocketService <ScoresDirectManager>("/scoresDirect", () => new ScoresDirectManager());
            GameManager gameManager = new GameManager(lobbies);

            Console.WriteLine("Starting to check for sockets");
            // start game broadcasting service
            gameManager.startGame();
            Console.ReadKey(true);
            wssv.Stop();
        }
Esempio n. 15
0
 public static void Help()
 {
     Prints.HelpManual();
 }
Esempio n. 16
0
    /**
     * #function Bot::GetFit |
     * @author JavaComSci |
     * @desc gets the fit of a single block onboard |
     * @header public List<CompatiblePiece> GetFit(Board board, Block block) |
     * @param Board board: board to do placing on |
     * @param Block block: block to be placed|
     * @returns List<CompatiblePiece> : contains list of compatible positions for the block |
     */
    public List <CompatiblePiece> GetFit(Board board, Block block)
    {
        Prints botInfoPrinter = new Prints();

        // Console.WriteLine("GET FIT");
        // Console.WriteLine("NUMBER OF ROWS AND COLS " + board.height + " " + board.width);

        List <CompatiblePiece> compatiblePieces = new List <CompatiblePiece>();

        int[][] shiftedOverPiece = block.data;
        // botInfoPrinter.PrintJaggedArr(block.data);
        int[] bottomBlocks = block.GetBottomBlocksAsJaggedArray(block.data);

        // Console.WriteLine("AFTER JAGGED");

        // to calculate the width of the piece
        int minCol = 5;
        int maxCol = -1;

        // positions of where the piece exists in the data in a tuple with both the ints for row and column
        List <Tuple <int, int> > dotPositions = new List <Tuple <int, int> >();

        // go through all the rows and get all the places where there is a true
        for (int row = 0; row < block.data.Length; row++)
        {
            dotPositions.AddRange(block.data[row].Select((b, i) => b == 1 ? i : -1).Where(i => i != -1).Select(index => new Tuple <int, int>(row, index)));
        }

        // shift over the dot positions
        foreach (Tuple <int, int> positionOfDot in dotPositions)
        {
            // dot to be tested
            int dotRowOnPiece = positionOfDot.Item1;
            int dotColOnPiece = positionOfDot.Item2;
            // calculate the min and max of the columns
            minCol = Math.Min(minCol, dotColOnPiece);
            maxCol = Math.Max(maxCol, dotColOnPiece);
        }

        // find width of piece
        int widthOfPiece = maxCol - minCol + 1;

        for (int startingCol = 0; startingCol < board.board.GetLength(1) - widthOfPiece + 1; startingCol++)
        {
            for (int startingRow = board.maxHeights[startingCol] + 1; startingRow <= board.height; startingRow++)
            {
                // compatible board info
                List <Tuple <int, int> > compatibleBoard = new List <Tuple <int, int> >();


                // modified board that is getting filled by these dots
                int[,] modifiedBoardWithOnlyPieces = new int[board.height, board.width];

                for (int i = 0; i < board.height; i++)
                {
                    for (int j = 0; j < board.width; j++)
                    {
                        modifiedBoardWithOnlyPieces[i, j] = board.board[i, j];
                    }
                }

                // dots nearby for area covered
                HashSet <Tuple <int, int> > dotsNearby = new HashSet <Tuple <int, int> >();

                // dots that fill the floor
                int dotsFillingFloor = 0;

                // see if all dots can be placed on the board without indexing issues in the column space
                foreach (Tuple <int, int> shiftedDotPosition in dotPositions)
                {
                    int shiftedDotRow = shiftedDotPosition.Item1;
                    int shiftedDotCol = shiftedDotPosition.Item2;

                    // shifted on the board size for the dot to be on the board
                    int shiftedForBoardRow = board.height + (shiftedDotRow - bottomBlocks[0]) - startingRow;
                    int shiftedForBoardCol = startingCol + shiftedDotCol;

                    // make sure that the shifted piece is not below the possibile pieces already there
                    if (board.height - board.maxHeights[startingCol + shiftedDotCol] <= shiftedForBoardRow)
                    {
                        compatibleBoard = null;
                        break;
                    }

                    // check whether the 2 heights are more than height of the board, if yes, then should not continue with the piece in this or any of the following rows
                    if (shiftedForBoardRow < 0 || shiftedForBoardRow >= board.height)
                    {
                        compatibleBoard = null;
                        break;
                    }

                    // check if the dot is overriding an exising dot
                    if (board.board[shiftedForBoardRow, shiftedForBoardCol] == 1)
                    {
                        compatibleBoard = null;
                        break;
                    }

                    // add to the board information
                    compatibleBoard.Add(Tuple.Create(shiftedForBoardRow, shiftedForBoardCol));
                    // Console.WriteLine("HERE " + shiftedForBoardRow + " " + shiftedForBoardCol);
                    modifiedBoardWithOnlyPieces[shiftedForBoardRow, shiftedForBoardCol] = 2;

                    // Console.WriteLine("SHIFTED " + shiftedForBoardRow + " " + shiftedForBoardCol + " " + modifiedBoardWithOnlyPieces.GetLength(1));
                    // see which dots are nearby
                    // up
                    if (shiftedForBoardRow - 1 > 0 && board.board[shiftedForBoardRow - 1, shiftedForBoardCol] == 1)
                    {
                        dotsNearby.Add(Tuple.Create(shiftedForBoardRow - 1, shiftedForBoardCol));
                    }
                    // down
                    if (shiftedForBoardRow + 1 < board.height && board.board[shiftedForBoardRow + 1, shiftedForBoardCol] == 1)
                    {
                        dotsNearby.Add(Tuple.Create(shiftedForBoardRow + 1, shiftedForBoardCol));
                    }
                    // left
                    if (shiftedForBoardCol - 1 >= 0 && board.board[shiftedForBoardRow, shiftedForBoardCol - 1] == 1)
                    {
                        dotsNearby.Add(Tuple.Create(shiftedForBoardRow, shiftedForBoardCol - 1));
                    }
                    // right
                    if (shiftedForBoardCol + 1 < board.width && board.board[shiftedForBoardRow, shiftedForBoardCol + 1] == 1)
                    {
                        dotsNearby.Add(Tuple.Create(shiftedForBoardRow, shiftedForBoardCol + 1));
                    }
                    // check for touching the floor
                    if (shiftedForBoardRow + 1 == board.height)
                    {
                        dotsNearby.Add(Tuple.Create(shiftedForBoardRow + 1, shiftedForBoardCol));
                        dotsFillingFloor += 1;
                    }

                    // check for touching the ceiling
                    if (shiftedForBoardRow - 1 == 0)
                    {
                        dotsNearby.Add(Tuple.Create(shiftedForBoardRow - 1, shiftedForBoardCol));
                    }
                }

                // piece starting at this column and row is actually compatible then add its information
                if (compatibleBoard != null)
                {
                    // check for the number of rows that it fills
                    int rowsFilled = 0;
                    for (int k = 0; k < board.height; k++)
                    {
                        bool allFilled = true;
                        for (int l = 0; l < board.width; l++)
                        {
                            if (modifiedBoardWithOnlyPieces[k, l] != 1 && modifiedBoardWithOnlyPieces[k, l] != 2)
                            {
                                allFilled = false;
                            }
                        }
                        if (allFilled)
                        {
                            rowsFilled += 1;
                        }
                    }

                    compatibleBoard = compatibleBoard.OrderBy(c => c.Item1).ThenBy(c => c.Item2).ToList();
                    CompatiblePiece compatiblePiece = new CompatiblePiece(compatibleBoard, dotsNearby.Count, rowsFilled);
                    compatiblePieces.Add(compatiblePiece);
                    break;
                }
            }
        }
        // Console.WriteLine("RETURNING IS " + compatiblePieces);
        return(compatiblePieces);
    }
Esempio n. 17
0
    public void stateUpdate()
    {
        while (true)
        {
            Thread.Sleep(1000); // tick rate

            foreach (string lobbyID in lobbies.Keys.ToList())
            {
                Lobby lobby = lobbies[lobbyID];
                if (lobby.lobbyState == LobbyState.PLAYING)
                {
                    if (lobby.bot != null)
                    {
                        Bot bot = lobby.bot;
                        Console.WriteLine("making bot move");
                        Board modifiedBoard = new Board(lobby.game.board.height, lobby.game.board.width);
                        for (int i = 0; i < lobby.game.board.height; i++)
                        {
                            for (int j = 0; j < lobby.game.board.width; j++)
                            {
                                if (lobby.game.board.board[i, j] >= 1)
                                {
                                    // Console.WriteLine("THE INDEX IS " + i + " " + j + " " + lobby.game.board.board[i, j]);
                                    modifiedBoard.board[i, j] = 1;
                                }
                                else
                                {
                                    modifiedBoard.board[i, j] = 0;
                                }
                            }
                        }

                        Prints botInfoPrinter = new Prints();
                        // Console.WriteLine("BEFORE BOT BOARD");
                        // botInfoPrinter.PrintMultiDimArr(modifiedBoard.board);
                        allBlocks[0].RemoveAt(0);
                        allBlocks[0].Add(new Block(randomPiece.GenerateRandomPiece(), 1));
                        allBlocks[1].RemoveAt(0);
                        allBlocks[1].Add(new Block(randomPiece.GenerateRandomPiece(), 1));
                        allBlocks[2].RemoveAt(0);
                        allBlocks[2].Add(new Block(randomPiece.GenerateRandomPiece(), 1));


                        List <Tuple <int, int> > bob;
                        try
                        {
                            SingleBot singleBot = new SingleBot();
                            List <List <Tuple <int, int> > > allBobs = singleBot.GetMove(modifiedBoard, allBlocks);
                            bob = allBobs[0];

                            if (bot is DoubleBot || bot is TripleBot)
                            {
                                Console.WriteLine("I AM A DOUBLE BOT!!");
                                int[,] newBoard = new int[modifiedBoard.board.GetLength(0), modifiedBoard.board.GetLength(1)];

                                for (int i = 0; i < modifiedBoard.board.GetLength(0); i++)
                                {
                                    for (int j = 0; j < modifiedBoard.board.GetLength(1); j++)
                                    {
                                        newBoard[i, j] = modifiedBoard.board[i, j];
                                    }
                                }

                                foreach (Tuple <int, int> dot in bob)
                                {
                                    newBoard[dot.Item1, dot.Item2] = 1;
                                }

                                Board nBoard = new Board(newBoard.GetLength(0), newBoard.GetLength(1));
                                nBoard.board = newBoard;
                                List <List <Tuple <int, int> > > newBobs = singleBot.GetMove(nBoard, allBlocks);
                                if (newBobs != null)
                                {
                                    bob.AddRange(newBobs[0]);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            bob = null;
                        }

                        // List<List<Tuple<int, int>>> allBobs = bot.GetMove(modifiedBoard, allBlocks);
                        // List<Tuple<int, int>> bob = allBobs[0];
                        if (bob == null)
                        {
                            Console.WriteLine("no place to place piece");
                            return;
                        }
                        else
                        {
                            Console.WriteLine("bot move?!@#\n\n\n");
                            bool moveValid = true;
                            // foreach (Tuple<int, int> tup in bob)
                            // {
                            //     foreach (Player player in lobby.players)
                            //     {
                            //         if (player.currentBlockPosition != null)
                            //         {
                            //             for (int i = 0; i < player.currentBlockPosition.Length; i++)
                            //             {
                            //                 if (tup.Item1 == player.currentBlockPosition[i][0] && tup.Item2 == player.currentBlockPosition[i][1])
                            //                 {
                            //                     moveValid = false;
                            //                 }
                            //             }
                            //         }
                            //     }
                            // }
                            if (moveValid)
                            {
                                foreach (Tuple <int, int> tup in bob)
                                {
                                    lobby.game.board.board[tup.Item1, tup.Item2] = 1;
                                }
                            }
                        }
                    }


                    // update board
                    for (int j = 0; j < lobby.players.Count; j++)
                    {
                        if (lobby.players[j].currentBlock == null)
                        {
                            // spawn block
                            // lobby.players[j].currentBlock = new Block(data, 5);
                            // lobby.players[j].currentBlockPosition = new Tuple<int, int>(5, 5);
                        }
                        else
                        {
                            if (checkCollision(lobby.players[j], lobby.game.board))
                            {
                                // place block
                                // set player's current block to null
                            }
                            // block falls 1 space
                            // lobby.players[j].currentBlockPosition = new Tuple<int, int>(lobby.players[j].currentBlockPosition.Item1 - 1, lobby.players[j].currentBlockPosition.Item2);
                        }
                    }
                    lobby.game.current_time += 1;
                    // send game state to all players in lobby
                    for (int j = 0; j < lobby.players.Count; j++)
                    {
                        lobby.players[j].webSocket.Send(JsonConvert.SerializeObject(lobby.game));
                    }
                }
            }
        }
    }
 public PrintListViewModel()
 {
     // Populate with some dummy data
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 1", ModelName = "Name 1", ModelDescription1 = "Description 1", ModelDescription2 = "Description 1", ModelDescription3 = "Description 1", ModelDescription4 = "Description 1", ModelDescription5 = "Description 1", ModelDescription6 = "Description 1", ModelDescription7 = "Description 1", ModelDescription8 = "Description 1", ModelDescription9 = "Description 1", ModelDescription10 = "Description 1", ModelDescription11 = "Description 1", ModelDescription12 = "Description 1"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 2", ModelName = "Name 2", ModelDescription1 = "Description 2", ModelDescription2 = "Description 2", ModelDescription3 = "Description 2", ModelDescription4 = "Description 2", ModelDescription5 = "Description 2", ModelDescription6 = "Description 2", ModelDescription7 = "Description 2", ModelDescription8 = "Description 2", ModelDescription9 = "Description 2", ModelDescription10 = "Description 2", ModelDescription11 = "Description 2", ModelDescription12 = "Description 2"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
     Prints.Add(new PrintModel()
     {
         ModelDescription = "Description 3", ModelName = "Name 3", ModelDescription1 = "Description 3", ModelDescription2 = "Description 3", ModelDescription3 = "Description 3", ModelDescription4 = "Description 3", ModelDescription5 = "Description 3", ModelDescription6 = "Description 3", ModelDescription7 = "Description 3", ModelDescription8 = "Description 3", ModelDescription9 = "Description 3", ModelDescription10 = "Description 3", ModelDescription11 = "Description 3", ModelDescription12 = "Description 3"
     });
 }
Esempio n. 19
0
 public TripleBot()
 {
     // create a board for this bot
     Console.WriteLine("I AM A TRIPLE BOT");
     botInfoPrinter = new Prints();
 }