#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <iostream> #include <queue> using namespace std; struct Agent { int direction; int row; int col; int scareDuration; bool isAlive; Agent() {}; Agent(int _row, int _col, bool _isAlive) :row(_row), col(_col), isAlive(_isAlive) { direction = 0; scareDuration = 0; } }; struct Information { int colSize; int rowSize; char map[31][58]; Agent pacman; Agent ghost[4]; int numGhost; }; extern int getAction(Information info_Data); extern void init(); extern void gameOver(Information data); Information info = { 0 }, init_info = { 0 }; int score = 0; int init_remainFood = 0, remainFood = 0; bool collisionCheck(int row, int col, Information & data) { if (row < 0 || col < 0 || (data.map[row][col] == 'X')) { return false; } return true; } void onUpdate(Agent& who, bool isGhost) { int direction[4]; int top = 0; int pos[4][2] = { { -1, 0 },{ 0, -1 },{ 1, 0 },{ 0, 1 } }; for (int i = 0; i < 4; i++) { int row = who.row + pos[i][0]; int col = who.col + pos[i][1]; if (collisionCheck(row, col, info) == true) { direction[top++] = i; } } int nextAction = 0; nextAction = getAction(info); for (int i = 0; i < top; i++) { if (nextAction == direction[i]) { who.direction = nextAction; who.row += pos[nextAction][0]; who.col += pos[nextAction][1]; return; } } return; } bool play() { int ghostScore = 200; /* * - 게임 종료 조건 - * 1.점수가 -500이 될 경우 게임을 종료하고 패배한다. * 2. 모든 food를 먹었을 경우 게임을 종료하고 승리한다. */ if (remainFood <= 0) { gameOver(info); return false; } if ((score -= 5) <= -500) { gameOver(info); return false; } onUpdate(info.pacman, false); if (info.map[info.pacman.row][info.pacman.col] == '.') { score += 10; remainFood--; info.map[info.pacman.row][info.pacman.col] = '_'; } else if (info.map[info.pacman.row][info.pacman.col] == 'O') { score += 500; remainFood--; info.map[info.pacman.row][info.pacman.col] = '_'; } return true; } int main() { freopen("input.txt", "r", stdin); int T = 0; scanf("%d %d %d", &init_info.rowSize, &init_info.colSize, &T); for (int row = 0; row < init_info.rowSize; row++) { scanf("%s", init_info.map[row]); for (int col = 0; col < init_info.colSize; col++) { if (init_info.map[row][col] == 'P') { init_info.pacman = Agent(row, col, true); init_info.map[row][col] = '_'; } else if (init_info.map[row][col] == '.' || init_info.map[row][col] == 'O') { init_remainFood++; } } } long long int totalScore = 0; for (int test_case = 1; test_case <= T; test_case++) { score = 0; info = init_info; remainFood = init_remainFood; init(); bool run = true; while (run) { run = play(); } printf("#%d %d\n", test_case, score); totalScore += score; } printf("totalScore : %lld\n", totalScore); return 0; }
|
#define UP 0 #define LEFT 1 #define DOWN 2 #define RIGHT 3 /* * ===게임 캐릭터를 위한 구조체=== * direction : 현재 캐릭터가 바라보고 있는 방향 * row, col : 캐릭터의 위치 * scareDuration : -고스트만 사용- 팩맨이 고스트를 잡아먹을 수 있는 시간 * isAlive : 캐릭터가 죽었는지 살아있는지 표시 */ struct Agent { int direction; int row; int col; int scareDuration; bool isAlive; Agent() {}; Agent(int _row, int _col, bool _isAlive) :row(_row), col(_col), isAlive(_isAlive) { direction = 0; scareDuration = 0; } }; /* * === 게임 정보를 위한 구조체 === * colSize, rowSize : 맵의 가로길이 세로길이 * map[31][58] : 맵 정보 * pacman : 팩맨 정보 * ghost[4] : 고스트 정보 * numGhost : 고스트의 갯수 */ struct Information { int colSize; int rowSize; char map[31][58]; Agent pacman; Agent ghost[4]; int numGhost; int score; }; void init() { } int getAction(Information info) { return RIGHT; } void gameOver(Information data) { } |
31 28 1 2333333333333423333333333334 1............11............1 1.2334.23334.11.23334.2334.1 1O1__1.1___1.11.1___1.1__1O1 1.6335.63335.65.63335.6335.1 1..........................1 1.2334.24.23333334.24.2334.1 1.6335.11.63342335.11.6335.1 1......11....11....11......1 633334.16334.11.23351.233335 _____1.12335.65.63341.1_____ _____1.11__________11.1_____ _____1.11_2______4_11.1_____ _____1.65_1______1_65.1_____ _____1.___1______1___.1_____ _____1.24_1______1_24.1_____ _____1.11_63333335_11.1_____ _____1.11__________11.1_____ _____1.11_23333334_11.1_____ 233335.65_63342335_65.633334 1............11............1 1.2334.23334.11.23334.2334.1 1.6341.63335.65.63335.1235.1 1O..11.......P........11..O1 634.11.24.23333334.24.11.235 235.65.11.63342335.11.65.634 1......11....11....11......1 1.2333356334.11.2335633334.1 1.6333333335.65.6333333335.1 1..........................1 6333333333333333333333333335 |
'Computer Science' 카테고리의 다른 글
빠른 휴대전화 키패드 (0) | 2019.02.18 |
---|---|
정식이의 은행업무 (0) | 2019.02.18 |
모음이 보이지 않는 사람 (0) | 2019.02.13 |
세상의 모든 팰린드롬 (0) | 2019.02.13 |
세상의 모든 팰린드롬 2 (0) | 2019.02.13 |
댓글