0

I want to place the following shape in the map I created. to the top. but I couldn't find how to set up the algorithm for it.

my map ;                                             i want to this shape:

xxxxxxxxxxxx    shape = {{"T","T","T"},               xxxxxxxxxxxxxxxx
x          x             {" ","T"," "}};              x    TTT       x
x          x                                          x     T        x
x          x                                          x              x
x          x                                          x              x
xxxxxxxxxxxx                                          xxxxxxxxxxxxxxxx
    int i,j;
int heigth,width;
vector<vector<char>> board;
vector<vector<char>>shape;
vector<char>deneme;
shape = {{' ', ' ', ' ', ' '},
    {' ', ' ', ' ', ' '},
     {'T', 'T', 'T', ' '},
     {' ', 'T', ' ', ' '}};
`

    for(i=0; i<height; i++)
    {
        for(j=0; j<width; j++)
        {
    deneme.push_back(' ');
        }
            board.push_back(deneme);
    }
    for(i=0; i<width; i++)
    {
        for(j=0; j<height; j++)
        {
            if(j==0 || j==height-1)
            {
              
                board[i][j]='x';
            }
            if(i==0 || i==width-1 )
            {
                board[i][j]='x';
            }   
        }
    }
463035818_is_not_an_ai
  • 109,796
  • 11
  • 89
  • 185
nwer
  • 1
  • Your are not using your `shape` anywhere in your code, so of course it doesn't appear. Just substitute your whitespaces `' '` with your shape in correct positions. You just need to ask yourself what is "correct" position first, and what is the point of reference in the shape: center of the shape, upper-left corner of the shape? – pptaszni Nov 03 '22 at 09:40
  • Your first loop results of lines of lenghts `width`, `2* width`, `3 * width`, ... . Btw: how do you determine the position of the shape? Also why od you use logic running in `O(width*height)` for setting the `x`s, instead of the one running in `O(width + height)`? There's random padding at the top and the right and there don't seem any variables indicating the x/y position the shape should be placed at. – fabian Nov 03 '22 at 09:41
  • OMG using nested `vector<>` template for constant arrays of the same small resolution ... check this out [my old C++/VCL Tetris example](https://stackoverflow.com/a/53516557/2521214) for some inspiration especially pay attention to `BYTE shp[7*16]` variable (I know it could be `const` but it was coded with very beginner programmers during first class so I did not want to confuse them too much) ... just ignore the VCL stuff and rendering – Spektre Nov 04 '22 at 07:55

0 Answers0