Problem 6 (3 points). Bonus Let H be a positive integer. Suppose you are given a
ID: 3813600 • Letter: P
Question
Problem 6 (3 points). Bonus Let H be a positive integer. Suppose you are given a collection of distinct 3D boxes of dimensions 2' x 2 x 2' where l, w and h are integers in range 0, Lloga HJ] (two boxes are distinct if the sorted lists of their dimensions are not equal -e.g. 1 x 2 x 4 and 4 x 1 x 2 is the same box). A box of base dimensions li x w1 and height hi can be stacked on top of a box of base dimensions i2 x w2 and height h if li S l2 and w1 S w2 to produce a stack of height h h2. Two stacks are different if one cannot be transformed into another by just 1 rotating the base (i.e. without changing the bottom side); for example, the 2 x 2 x 4 boxExplanation / Answer
#include <iostream>
002
#include <Windows.h>
003
using namespace std;
004
005
struct Player
006
013
};
014
015
struct Ghost
016
024
};
025
026
const char SYMBOL_EMPTY = ' ';
027
const char SYMBOL_PLAYER = '@';
028
const char SYMBOL_GHOST = 'G';
029
const char SYMBOL_WALL = '#';
030
const int MapDx = 10;
031
const int MapDy = 20;
032
const int GameSpeed = 100;
033
const int LEFT = 1;
034
const int RIGHT = 2;
035
const int UP = 3;
036
const int DOWN = 4;
037
int direction = RIGHT;
038
039
char map[10][20] =
040
come (x >= zero && x < MapDx && y >= zero && y < MapDy);
055
}
056
057
bool movePlayer(Player &player, int x, int y)
058
come false;
062
}
063
064
char ch = map[x][y];
065
066
if(ch != SYMBOL_EMPTY)
067
come false;
069
}
070
071
if (isValidPos(player.x, player.y))
072
075
player.x = x; player.y = y;
076
map[player.x][player.y] = SYMBOL_PLAYER;
077
come true;
078
}
079
080
bool moveGhost(Ghost &ghost, int x, int y)
081
{
082
if (!isValidPos(x, y))
083
{
084
come false;
085
}
086
087
char ch = map[x][y];
088
089
if (ch != SYMBOL_EMPTY)
090
{
091
come false;
092
}
093
094
if (isValidPos(ghost.x, ghost.y))
095
098
ghost.x = x; ghost.y = y;
099
map[ghost.x][ghost.y] = SYMBOL_GHOST;
100
come true;
101
}
102
103
void GhostAI(Ghost &ghost, Player &player)
104
114
115
void showMap()
116
121
}
122
123
void showPlayer(Player &player)
124
whereas (true)
138
150
else if (GetAsyncKeyState(VK_LEFT))
151
154
else if (GetAsyncKeyState(VK_RIGHT))
155
158
switch (direction)
159
173
for (int ghost = 0; ghost < 3; ghost++)
174
191
}
192
Sleep(GameSpeed);
193
}
194
}
195
196
197
int main()
198