Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

새싹교실/2015/새벽반/0518: Difference between revisions

From ZeroWiki
imported>woojin818
No edit summary
(Repair batch-0005 pages from live compare)
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
= 참여자 =
= 참여자 =
{| class="wikitable"
{| class="wikitable" style="width:100%;"
|-
|-
| 강사
| 강사
Line 9: Line 9:
|-
|-
| [[장우진]]
| [[장우진]]
| [[:새싹교실/2015/새벽반 /새벽반]]
| :새싹교실/2015/새벽반 /새벽반
| [[박성훈]]
| [[박성훈]]
| [[조원희]]
| [[조원희]]
Line 24: Line 24:
= 진행상황 =
= 진행상황 =


배열과 포인터에 대한 설명
* 배열과 포인터에 대한 설명
* 포인터를 가지고 연산 하기
* call by reference?
* call by value?
* 질의응답
 
= 과제 =
= 과제 =


 
* 틱택토!!!
* 마지막 과제입니다. 어려운거 해봅시다
* 한 줄 빙고를 만들면 이기는 간단한 게임
* 사용자와 컴퓨터가 대전
* 선 플레이어 설정 기능과 난이도 설정 기능 구현
* 간단한 GUI...
=== 박성훈 ===
=== 박성훈 ===
  #include <time.h>
  #include <time.h>
Line 40: Line 50:
  int computerwin();
  int computerwin();
  int draw();
  int draw();
  int full[9] = { 0, };
  int full[9] = { 0, };
  char matrix[3][3] = { '1', '2', '3', '4', '5', '6', '7', '8', '9' };
  char matrix[3][3] = { '1', '2', '3', '4', '5', '6', '7', '8', '9' };
   
   
   
   
Line 76: Line 86:
  for (;;){
  for (;;){
  printf("┌─┬─┬─┐\n");
  printf("┌─┬─┬─┐\n");
  printf("│%c │%c │%c │\n", matrix[0][0], matrix[0][1], matrix[0][2]);
  printf("│%c │%c │%c │\n", matrix[0][0], matrix[0][1], matrix[0][2]);
  printf("├─┼─┼─┤\n");
  printf("├─┼─┼─┤\n");
  printf("│%c │%c │%c │\n", matrix[1][0], matrix[1][1], matrix[1][2]);
  printf("│%c │%c │%c │\n", matrix[1][0], matrix[1][1], matrix[1][2]);
  printf("├─┼─┼─┤\n");
  printf("├─┼─┼─┤\n");
  printf("│%c │%c │%c │\n", matrix[2][0], matrix[2][1], matrix[2][2]);
  printf("│%c │%c │%c │\n", matrix[2][0], matrix[2][1], matrix[2][2]);
  printf("└─┴─┴─┘\n");
  printf("└─┴─┴─┘\n");
   
   
Line 108: Line 118:
  else if (levelfirst == 4)
  else if (levelfirst == 4)
  {
  {
  if (full[4] == 0)
  if (full[4] == 0)
  {
  {
  matrix[1][1] = 'X';
  matrix[1][1] = 'X';
  full[4] = 2;
  full[4] = 2;
  levelfirst = 3;
  levelfirst = 3;
  }
  }
Line 128: Line 138:
  system("cls");
  system("cls");
  printf("┌─┬─┬─┐\n");
  printf("┌─┬─┬─┐\n");
  printf("│%c │%c │%c │\n", matrix[0][0], matrix[0][1], matrix[0][2]);
  printf("│%c │%c │%c │\n", matrix[0][0], matrix[0][1], matrix[0][2]);
  printf("├─┼─┼─┤\n");
  printf("├─┼─┼─┤\n");
  printf("│%c │%c │%c │\n", matrix[1][0], matrix[1][1], matrix[1][2]);
  printf("│%c │%c │%c │\n", matrix[1][0], matrix[1][1], matrix[1][2]);
  printf("├─┼─┼─┤\n");
  printf("├─┼─┼─┤\n");
  printf("│%c │%c │%c │\n", matrix[2][0], matrix[2][1], matrix[2][2]);
  printf("│%c │%c │%c │\n", matrix[2][0], matrix[2][1], matrix[2][2]);
  printf("└─┴─┴─┘\n");
  printf("└─┴─┴─┘\n");
  printf("YOU WIN!!!\n");
  printf("YOU WIN!!!\n");
Line 140: Line 150:
  system("cls");
  system("cls");
  printf("┌─┬─┬─┐\n");
  printf("┌─┬─┬─┐\n");
  printf("│%c │%c │%c │\n", matrix[0][0], matrix[0][1], matrix[0][2]);
  printf("│%c │%c │%c │\n", matrix[0][0], matrix[0][1], matrix[0][2]);
  printf("├─┼─┼─┤\n");
  printf("├─┼─┼─┤\n");
  printf("│%c │%c │%c │\n", matrix[1][0], matrix[1][1], matrix[1][2]);
  printf("│%c │%c │%c │\n", matrix[1][0], matrix[1][1], matrix[1][2]);
  printf("├─┼─┼─┤\n");
  printf("├─┼─┼─┤\n");
  printf("│%c │%c │%c │\n", matrix[2][0], matrix[2][1], matrix[2][2]);
  printf("│%c │%c │%c │\n", matrix[2][0], matrix[2][1], matrix[2][2]);
  printf("└─┴─┴─┘\n");
  printf("└─┴─┴─┘\n");
  printf("You lose...\n");
  printf("You lose...\n");
Line 152: Line 162:
  system("cls");
  system("cls");
  printf("┌─┬─┬─┐\n");
  printf("┌─┬─┬─┐\n");
  printf("│%c │%c │%c │\n", matrix[0][0], matrix[0][1], matrix[0][2]);
  printf("│%c │%c │%c │\n", matrix[0][0], matrix[0][1], matrix[0][2]);
  printf("├─┼─┼─┤\n");
  printf("├─┼─┼─┤\n");
  printf("│%c │%c │%c │\n", matrix[1][0], matrix[1][1], matrix[1][2]);
  printf("│%c │%c │%c │\n", matrix[1][0], matrix[1][1], matrix[1][2]);
  printf("├─┼─┼─┤\n");
  printf("├─┼─┼─┤\n");
  printf("│%c │%c │%c │\n", matrix[2][0], matrix[2][1], matrix[2][2]);
  printf("│%c │%c │%c │\n", matrix[2][0], matrix[2][1], matrix[2][2]);
  printf("└─┴─┴─┘\n");
  printf("└─┴─┴─┘\n");
  printf("Draw\n");
  printf("Draw\n");
Line 181: Line 191:
  if (place == 1)
  if (place == 1)
  {
  {
  if (full[0] == 0)
  if (full[0] == 0)
  {
  {
  matrix[0][0] = 'O';
  matrix[0][0] = 'O';
  full[0] = 1;
  full[0] = 1;
  playerturnfinish = 1;
  playerturnfinish = 1;
  }
  }
  else if (full[0] == 1 || full[0] == 2)
  else if (full[0] == 1 || full[0] == 2)
  {
  {
  printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
  printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
Line 195: Line 205:
  else if (place == 2)
  else if (place == 2)
  {
  {
  if (full[1] == 0)
  if (full[1] == 0)
  {
  {
  matrix[0][1] = 'O';
  matrix[0][1] = 'O';
  full[1] = 1;
  full[1] = 1;
  playerturnfinish = 1;
  playerturnfinish = 1;
  }
  }
  else if (full[1] == 1 || full[1] == 2)
  else if (full[1] == 1 || full[1] == 2)
  {
  {
  printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
  printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
Line 209: Line 219:
  else if (place == 3)
  else if (place == 3)
  {
  {
  if (full[2] == 0)
  if (full[2] == 0)
  {
  {
  matrix[0][2] = 'O';
  matrix[0][2] = 'O';
  full[2] = 1;
  full[2] = 1;
  playerturnfinish = 1;
  playerturnfinish = 1;
  }
  }
  else if (full[2] == 1 || full[2] == 2)
  else if (full[2] == 1 || full[2] == 2)
  {
  {
  printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
  printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
Line 223: Line 233:
  else if (place == 4)
  else if (place == 4)
  {
  {
  if (full[3] == 0)
  if (full[3] == 0)
  {
  {
  matrix[1][0] = 'O';
  matrix[1][0] = 'O';
  full[3] = 1;
  full[3] = 1;
  playerturnfinish = 1;
  playerturnfinish = 1;
  }
  }
  else if (full[3] == 1 || full[3] == 2)
  else if (full[3] == 1 || full[3] == 2)
  {
  {
  printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
  printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
Line 237: Line 247:
  else if (place == 5)
  else if (place == 5)
  {
  {
  if (full[4] == 0)
  if (full[4] == 0)
  {
  {
  matrix[1][1] = 'O';
  matrix[1][1] = 'O';
  full[4] = 1;
  full[4] = 1;
  playerturnfinish = 1;
  playerturnfinish = 1;
  }
  }
  else if (full[4] == 1 || full[4] == 2)
  else if (full[4] == 1 || full[4] == 2)
  {
  {
  printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
  printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
Line 251: Line 261:
  else if (place == 6)
  else if (place == 6)
  {
  {
  if (full[5] == 0)
  if (full[5] == 0)
  {
  {
  matrix[1][2] = 'O';
  matrix[1][2] = 'O';
  full[5] = 1;
  full[5] = 1;
  playerturnfinish = 1;
  playerturnfinish = 1;
  }
  }
  else if (full[5] == 1 || full[5] == 2)
  else if (full[5] == 1 || full[5] == 2)
  {
  {
  printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
  printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
Line 265: Line 275:
  else if (place == 7)
  else if (place == 7)
  {
  {
  if (full[6] == 0)
  if (full[6] == 0)
  {
  {
  matrix[2][0] = 'O';
  matrix[2][0] = 'O';
  full[6] = 1;
  full[6] = 1;
  playerturnfinish = 1;
  playerturnfinish = 1;
  }
  }
  else if (full[6] == 1 || full[6] == 2)
  else if (full[6] == 1 || full[6] == 2)
  {
  {
  printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
  printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
Line 279: Line 289:
  else if (place == 8)
  else if (place == 8)
  {
  {
  if (full[7] == 0)
  if (full[7] == 0)
  {
  {
  matrix[2][1] = 'O';
  matrix[2][1] = 'O';
  full[7] = 1;
  full[7] = 1;
  playerturnfinish = 1;
  playerturnfinish = 1;
  }
  }
  else if (full[7] == 1 || full[7] == 2)
  else if (full[7] == 1 || full[7] == 2)
  {
  {
  printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
  printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
Line 293: Line 303:
  else if (place == 9)
  else if (place == 9)
  {
  {
  if (full[8] == 0)
  if (full[8] == 0)
  {
  {
  matrix[2][2] = 'O';
  matrix[2][2] = 'O';
  full[8] = 1;
  full[8] = 1;
  playerturnfinish = 1;
  playerturnfinish = 1;
  }
  }
  else if (full[8] == 1 || full[8] == 2)
  else if (full[8] == 1 || full[8] == 2)
  {
  {
  printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
  printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
Line 321: Line 331:
  if (place == 1)
  if (place == 1)
  {
  {
  if (full[0] == 0)
  if (full[0] == 0)
  {
  {
  matrix[0][0] = 'X';
  matrix[0][0] = 'X';
  full[0] = 2;
  full[0] = 2;
  computerturnfinish = 1;
  computerturnfinish = 1;
  }
  }
  else if (full[0] == 1 || full[0] == 2)
  else if (full[0] == 1 || full[0] == 2)
  {
  {
 
 
Line 335: Line 345:
  else if (place == 2)
  else if (place == 2)
  {
  {
  if (full[1] == 0)
  if (full[1] == 0)
  {
  {
  matrix[0][1] = 'X';
  matrix[0][1] = 'X';
  full[1] = 2;
  full[1] = 2;
  computerturnfinish = 1;
  computerturnfinish = 1;
  }
  }
  else if (full[1] == 1 || full[1] == 2)
  else if (full[1] == 1 || full[1] == 2)
  {
  {
  continue;
  continue;
Line 348: Line 358:
  else if (place == 3)
  else if (place == 3)
  {
  {
  if (full[2] == 0)
  if (full[2] == 0)
  {
  {
  matrix[0][2] = 'X';
  matrix[0][2] = 'X';
  full[2] = 2;
  full[2] = 2;
  computerturnfinish = 1;
  computerturnfinish = 1;
  }
  }
  else if (full[2] == 1 || full[2] == 2)
  else if (full[2] == 1 || full[2] == 2)
  {
  {
 
 
Line 362: Line 372:
  else if (place == 4)
  else if (place == 4)
  {
  {
  if (full[3] == 0)
  if (full[3] == 0)
  {
  {
  matrix[1][0] = 'X';
  matrix[1][0] = 'X';
  full[3] = 2;
  full[3] = 2;
  computerturnfinish = 1;
  computerturnfinish = 1;
  }
  }
  else if (full[3] == 1 || full[3] == 2)
  else if (full[3] == 1 || full[3] == 2)
  {
  {
 
 
Line 376: Line 386:
  else if (place == 5)
  else if (place == 5)
  {
  {
  if (full[4] == 0)
  if (full[4] == 0)
  {
  {
  matrix[1][1] = 'X';
  matrix[1][1] = 'X';
  full[4] = 2;
  full[4] = 2;
  computerturnfinish = 1;
  computerturnfinish = 1;
  }
  }
  else if (full[4] == 1 || full[4] == 2)
  else if (full[4] == 1 || full[4] == 2)
  {
  {
 
 
Line 390: Line 400:
  else if (place == 6)
  else if (place == 6)
  {
  {
  if (full[5] == 0)
  if (full[5] == 0)
  {
  {
  matrix[1][2] = 'X';
  matrix[1][2] = 'X';
  full[5] = 2;
  full[5] = 2;
  computerturnfinish = 1;
  computerturnfinish = 1;
  }
  }
  else if (full[5] == 1 || full[5] == 2)
  else if (full[5] == 1 || full[5] == 2)
  {
  {
 
 
Line 404: Line 414:
  else if (place == 7)
  else if (place == 7)
  {
  {
  if (full[6] == 0)
  if (full[6] == 0)
  {
  {
  matrix[2][0] = 'X';
  matrix[2][0] = 'X';
  full[6] = 2;
  full[6] = 2;
  computerturnfinish = 1;
  computerturnfinish = 1;
  }
  }
  else if (full[6] == 1 || full[6] == 2)
  else if (full[6] == 1 || full[6] == 2)
  {
  {
 
 
Line 418: Line 428:
  else if (place == 8)
  else if (place == 8)
  {
  {
  if (full[7] == 0)
  if (full[7] == 0)
  {
  {
  matrix[2][1] = 'X';
  matrix[2][1] = 'X';
  full[7] = 2;
  full[7] = 2;
  computerturnfinish = 1;
  computerturnfinish = 1;
  }
  }
  else if (full[7] == 1 || full[7] == 2)
  else if (full[7] == 1 || full[7] == 2)
  {
  {
 
 
Line 432: Line 442:
  else if (place == 9)
  else if (place == 9)
  {
  {
  if (full[8] == 0)
  if (full[8] == 0)
  {
  {
  matrix[2][2] = 'X';
  matrix[2][2] = 'X';
  full[8] = 2;
  full[8] = 2;
  computerturnfinish = 1;
  computerturnfinish = 1;
  }
  }
  else if (full[8] == 1 || full[8] == 2)
  else if (full[8] == 1 || full[8] == 2)
  {
  {
 
 
Line 449: Line 459:
   
   
  int playerwin(){
  int playerwin(){
  if (full[0] ==1 && full[1] ==1 && full[2] == 1)
  if (full[0] ==1 && full[1] ==1 && full[2] == 1)
  return 1;
  return 1;
  else if (full[3] == 1 && full[4] == 1 && full[5] == 1)
  else if (full[3] == 1 && full[4] == 1 && full[5] == 1)
  return 1;
  return 1;
  else if (full[6] == 1 && full[7] == 1 && full[8] == 1)
  else if (full[6] == 1 && full[7] == 1 && full[8] == 1)
  return 1;
  return 1;
  else if (full[0] == 1 && full[3] == 1 && full[6] == 1)
  else if (full[0] == 1 && full[3] == 1 && full[6] == 1)
  return 1;
  return 1;
  else if (full[1] == 1 && full[4] == 1 && full[7] == 1)
  else if (full[1] == 1 && full[4] == 1 && full[7] == 1)
  return 1;
  return 1;
  else if (full[2] == 1 && full[5] == 1 && full[8] == 1)
  else if (full[2] == 1 && full[5] == 1 && full[8] == 1)
  return 1;
  return 1;
  else if (full[0] == 1 && full[4] == 1 && full[8] == 1)
  else if (full[0] == 1 && full[4] == 1 && full[8] == 1)
  return 1;
  return 1;
  else if (full[2] == 1 && full[4] == 1 && full[6] == 1)
  else if (full[2] == 1 && full[4] == 1 && full[6] == 1)
  return 1;
  return 1;
   
   
Line 469: Line 479:
   
   
  int computerwin(){
  int computerwin(){
  if (full[0] == 2 && full[1] == 2 && full[2] == 2)
  if (full[0] == 2 && full[1] == 2 && full[2] == 2)
  return 1;
  return 1;
  else if (full[3] == 2 && full[4] == 2 && full[5] == 2)
  else if (full[3] == 2 && full[4] == 2 && full[5] == 2)
  return 1;
  return 1;
  else if (full[6] == 2 && full[7] == 2 && full[8] == 2)
  else if (full[6] == 2 && full[7] == 2 && full[8] == 2)
  return 1;
  return 1;
  else if (full[0] == 2 && full[3] == 2 && full[6] == 2)
  else if (full[0] == 2 && full[3] == 2 && full[6] == 2)
  return 1;
  return 1;
  else if (full[1] == 2 && full[4] == 2 && full[7] == 2)
  else if (full[1] == 2 && full[4] == 2 && full[7] == 2)
  return 1;
  return 1;
  else if (full[2] == 2 && full[5] == 2 && full[8] == 2)
  else if (full[2] == 2 && full[5] == 2 && full[8] == 2)
  return 1;
  return 1;
  else if (full[0] == 2 && full[4] == 2 && full[8] == 2)
  else if (full[0] == 2 && full[4] == 2 && full[8] == 2)
  return 1;
  return 1;
  else if (full[2] == 2 && full[4] == 2 && full[6] == 2)
  else if (full[2] == 2 && full[4] == 2 && full[6] == 2)
  return 1;
  return 1;
   
   
Line 490: Line 500:
  int draw()
  int draw()
  {
  {
  if (full[0] != 0 && full[1] != 0 && full[2] != 0 && full[3] != 0 && full[4] != 0 && full[5] != 0 && full[6] != 0 && full[7] != 0 && full[8] != 0)
  if (full[0] != 0 && full[1] != 0 && full[2] != 0 && full[3] != 0 && full[4] != 0 && full[5] != 0 && full[6] != 0 && full[7] != 0 && full[8] != 0)
  {
  {
  return 1;
  return 1;
Line 520: Line 530:
  if (place == 1)
  if (place == 1)
  {
  {
  if (full[0] == 0)
  if (full[0] == 0)
  {
  {
  matrix[0][0] = 'X';
  matrix[0][0] = 'X';
  full[0] = 2;
  full[0] = 2;
  computerturnfinish = 1;
  computerturnfinish = 1;
  }
  }
  else if (full[0] == 1 || full[0] == 2)
  else if (full[0] == 1 || full[0] == 2)
  {
  {
   
   
Line 534: Line 544:
  else if (place == 2)
  else if (place == 2)
  {
  {
  if (full[1] == 0)
  if (full[1] == 0)
  {
  {
  matrix[0][1] = 'X';
  matrix[0][1] = 'X';
  full[1] = 2;
  full[1] = 2;
  computerturnfinish = 1;
  computerturnfinish = 1;
  }
  }
  else if (full[1] == 1 || full[1] == 2)
  else if (full[1] == 1 || full[1] == 2)
  {
  {
  continue;
  continue;
Line 547: Line 557:
  else if (place == 3)
  else if (place == 3)
  {
  {
  if (full[2] == 0)
  if (full[2] == 0)
  {
  {
  matrix[0][2] = 'X';
  matrix[0][2] = 'X';
  full[2] = 2;
  full[2] = 2;
  computerturnfinish = 1;
  computerturnfinish = 1;
  }
  }
  else if (full[2] == 1 || full[2] == 2)
  else if (full[2] == 1 || full[2] == 2)
  {
  {
   
   
Line 561: Line 571:
  else if (place == 4)
  else if (place == 4)
  {
  {
  if (full[3] == 0)
  if (full[3] == 0)
  {
  {
  matrix[1][0] = 'X';
  matrix[1][0] = 'X';
  full[3] = 2;
  full[3] = 2;
  computerturnfinish = 1;
  computerturnfinish = 1;
  }
  }
  else if (full[3] == 1 || full[3] == 2)
  else if (full[3] == 1 || full[3] == 2)
  {
  {
   
   
Line 575: Line 585:
  else if (place == 5)
  else if (place == 5)
  {
  {
  if (full[4] == 0)
  if (full[4] == 0)
  {
  {
  matrix[1][1] = 'X';
  matrix[1][1] = 'X';
  full[4] = 2;
  full[4] = 2;
  computerturnfinish = 1;
  computerturnfinish = 1;
  }
  }
  else if (full[4] == 1 || full[4] == 2)
  else if (full[4] == 1 || full[4] == 2)
  {
  {
   
   
Line 589: Line 599:
  else if (place == 6)
  else if (place == 6)
  {
  {
  if (full[5] == 0)
  if (full[5] == 0)
  {
  {
  matrix[1][2] = 'X';
  matrix[1][2] = 'X';
  full[5] = 2;
  full[5] = 2;
  computerturnfinish = 1;
  computerturnfinish = 1;
  }
  }
  else if (full[5] == 1 || full[5] == 2)
  else if (full[5] == 1 || full[5] == 2)
  {
  {
   
   
Line 603: Line 613:
  else if (place == 7)
  else if (place == 7)
  {
  {
  if (full[6] == 0)
  if (full[6] == 0)
  {
  {
  matrix[2][0] = 'X';
  matrix[2][0] = 'X';
  full[6] = 2;
  full[6] = 2;
  computerturnfinish = 1;
  computerturnfinish = 1;
  }
  }
  else if (full[6] == 1 || full[6] == 2)
  else if (full[6] == 1 || full[6] == 2)
  {
  {
   
   
Line 617: Line 627:
  else if (place == 8)
  else if (place == 8)
  {
  {
  if (full[7] == 0)
  if (full[7] == 0)
  {
  {
  matrix[2][1] = 'X';
  matrix[2][1] = 'X';
  full[7] = 2;
  full[7] = 2;
  computerturnfinish = 1;
  computerturnfinish = 1;
  }
  }
  else if (full[7] == 1 || full[7] == 2)
  else if (full[7] == 1 || full[7] == 2)
  {
  {
   
   
Line 631: Line 641:
  else if (place == 9)
  else if (place == 9)
  {
  {
  if (full[8] == 0)
  if (full[8] == 0)
  {
  {
  matrix[2][2] = 'X';
  matrix[2][2] = 'X';
  full[8] = 2;
  full[8] = 2;
  computerturnfinish = 1;
  computerturnfinish = 1;
  }
  }
  else if (full[8] == 1 || full[8] == 2)
  else if (full[8] == 1 || full[8] == 2)
  {
  {
   
   
Line 653: Line 663:
  int attack()
  int attack()
  {
  {
  if ((full[0] ==2 && full[1] ==2) &&full[2]==0)
  if ((full[0] ==2 && full[1] ==2) &&full[2]==0)
  {
  {
  full[2] = 2;
  full[2] = 2;
  matrix[0][2] = 'X';
  matrix[0][2] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[0] == 2 && full[2] == 2) && full[1] == 0)
  else if ((full[0] == 2 && full[2] == 2) && full[1] == 0)
  {
  {
  full[1] = 2;
  full[1] = 2;
  matrix[0][1] = 'X';
  matrix[0][1] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[1] == 2 && full[2] == 2) && full[0] == 0)
  else if ((full[1] == 2 && full[2] == 2) && full[0] == 0)
  {
  {
  full[0] = 2;
  full[0] = 2;
  matrix[0][0] = 'X';
  matrix[0][0] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[3] == 2 && full[4] == 2) && full[5] == 0)
  else if ((full[3] == 2 && full[4] == 2) && full[5] == 0)
  {
  {
  full[5] = 2;
  full[5] = 2;
  matrix[1][2] = 'X';
  matrix[1][2] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[3] == 2 && full[5] == 2) && full[4] == 0)
  else if ((full[3] == 2 && full[5] == 2) && full[4] == 0)
  {
  {
  full[4] = 2;
  full[4] = 2;
  matrix[1][1] = 'X';
  matrix[1][1] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[5] == 2 && full[4] == 2) && full[3] == 0)
  else if ((full[5] == 2 && full[4] == 2) && full[3] == 0)
  {
  {
  full[3] = 2;
  full[3] = 2;
  matrix[1][0] = 'X';
  matrix[1][0] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[6] == 2 && full[7] == 2) && full[8] == 0)
  else if ((full[6] == 2 && full[7] == 2) && full[8] == 0)
  {
  {
  full[8] = 2;
  full[8] = 2;
  matrix[2][2] = 'X';
  matrix[2][2] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[6] == 2 && full[8] == 2) && full[7] == 0)
  else if ((full[6] == 2 && full[8] == 2) && full[7] == 0)
  {
  {
  full[7] = 2;
  full[7] = 2;
  matrix[2][1] = 'X';
  matrix[2][1] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[8] == 2 && full[7] == 2) && full[6] == 0)
  else if ((full[8] == 2 && full[7] == 2) && full[6] == 0)
  {
  {
  full[6] = 2;
  full[6] = 2;
  matrix[2][0] = 'X';
  matrix[2][0] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[0] == 2 && full[3] == 2) && full[6] == 0)
  else if ((full[0] == 2 && full[3] == 2) && full[6] == 0)
  {
  {
  full[6] = 2;
  full[6] = 2;
  matrix[2][0] = 'X';
  matrix[2][0] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[0] == 2 && full[6] == 2) && full[3] == 0)
  else if ((full[0] == 2 && full[6] == 2) && full[3] == 0)
  {
  {
  full[3] = 2;
  full[3] = 2;
  matrix[1][0] = 'X';
  matrix[1][0] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[6] == 2 && full[3] == 2) && full[3] == 0)
  else if ((full[6] == 2 && full[3] == 2) && full[3] == 0)
  {
  {
  full[3] = 2;
  full[3] = 2;
  matrix[0][0] = 'X';
  matrix[0][0] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[1] == 2 && full[4] == 2) && full[7] == 0)
  else if ((full[1] == 2 && full[4] == 2) && full[7] == 0)
  {
  {
  full[7] = 2;
  full[7] = 2;
  matrix[2][1] = 'X';
  matrix[2][1] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[1] == 2 && full[7] == 2) && full[4] == 0)
  else if ((full[1] == 2 && full[7] == 2) && full[4] == 0)
  {
  {
  full[4] = 2;
  full[4] = 2;
  matrix[1][1] = 'X';
  matrix[1][1] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[7] == 2 && full[4] == 2) && full[1] == 0)
  else if ((full[7] == 2 && full[4] == 2) && full[1] == 0)
  {
  {
  full[1] = 2;
  full[1] = 2;
  matrix[0][1] = 'X';
  matrix[0][1] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[2] == 2 && full[5] == 2) && full[8] == 0)
  else if ((full[2] == 2 && full[5] == 2) && full[8] == 0)
  {
  {
  full[8] = 2;
  full[8] = 2;
  matrix[2][2] = 'X';
  matrix[2][2] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[2] == 2 && full[8] == 2) && full[5] == 0)
  else if ((full[2] == 2 && full[8] == 2) && full[5] == 0)
  {
  {
  full[5] = 2;
  full[5] = 2;
  matrix[1][2] = 'X';
  matrix[1][2] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[8] == 2 && full[5] == 2) && full[2] == 0)
  else if ((full[8] == 2 && full[5] == 2) && full[2] == 0)
  {
  {
  full[2] = 2;
  full[2] = 2;
  matrix[0][2] = 'X';
  matrix[0][2] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[0] == 2 && full[4] == 2)&& full[8] == 0)
  else if ((full[0] == 2 && full[4] == 2)&& full[8] == 0)
  {
  {
  full[8] = 2;
  full[8] = 2;
  matrix[2][2] = 'X';
  matrix[2][2] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[0] == 2 && full[8] == 2)&& full[4] == 0)
  else if ((full[0] == 2 && full[8] == 2)&& full[4] == 0)
  {
  {
  full[4] = 2;
  full[4] = 2;
  matrix[1][1] = 'X';
  matrix[1][1] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[8] == 2 && full[4] == 2) && full[0] == 0)
  else if ((full[8] == 2 && full[4] == 2) && full[0] == 0)
  {
  {
  full[0] = 2;
  full[0] = 2;
  matrix[0][0] = 'X';
  matrix[0][0] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[2] == 2 && full[4] == 2) && full[6] == 0)
  else if ((full[2] == 2 && full[4] == 2) && full[6] == 0)
  {
  {
  full[8] = 2;
  full[8] = 2;
  matrix[2][0] = 'X';
  matrix[2][0] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[2] == 2 && full[6] == 2)&& full[4] == 0)
  else if ((full[2] == 2 && full[6] == 2)&& full[4] == 0)
  {
  {
  full[8] = 2;
  full[8] = 2;
  matrix[1][1] = 'X';
  matrix[1][1] = 'X';
  return 1;
  return 1;
  }
  }
  else if ((full[6] == 2 && full[4] == 2) && full[2] == 0)
  else if ((full[6] == 2 && full[4] == 2) && full[2] == 0)
  {
  {
  full[2] = 2;
  full[2] = 2;
  matrix[0][2] = 'X';
  matrix[0][2] = 'X';
  return 1;
  return 1;
  }
  }
Line 804: Line 814:
  int protect()
  int protect()
  {
  {
  if (full[0] == 1 && full[1] == 1 && full[2] == 0)
  if (full[0] == 1 && full[1] == 1 && full[2] == 0)
  {
  {
  full[2] = 2;
  full[2] = 2;
  matrix[0][2] = 'X';
  matrix[0][2] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[0] == 1 && full[2] == 1 && full[1] == 0)
  else if (full[0] == 1 && full[2] == 1 && full[1] == 0)
  {
  {
  full[1] = 2;
  full[1] = 2;
  matrix[0][1] = 'X';
  matrix[0][1] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[1] == 1 && full[2] == 1 && full[0] == 0)
  else if (full[1] == 1 && full[2] == 1 && full[0] == 0)
  {
  {
  full[0] = 2;
  full[0] = 2;
  matrix[0][0] = 'X';
  matrix[0][0] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[3] == 1 && full[4] == 1 && full[5] == 0)
  else if (full[3] == 1 && full[4] == 1 && full[5] == 0)
  {
  {
  full[5] = 2;
  full[5] = 2;
  matrix[1][2] = 'X';
  matrix[1][2] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[3] == 1 && full[5] == 1 && full[4] == 0)
  else if (full[3] == 1 && full[5] == 1 && full[4] == 0)
  {
  {
  full[4] = 2;
  full[4] = 2;
  matrix[1][1] = 'X';
  matrix[1][1] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[5] == 1 && full[4] == 1 && full[3] == 0)
  else if (full[5] == 1 && full[4] == 1 && full[3] == 0)
  {
  {
  full[3] = 2;
  full[3] = 2;
  matrix[1][0] = 'X';
  matrix[1][0] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[6] == 1 && full[7] == 1 && full[8] == 0)
  else if (full[6] == 1 && full[7] == 1 && full[8] == 0)
  {
  {
  full[8] = 2;
  full[8] = 2;
  matrix[2][2] = 'X';
  matrix[2][2] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[6] == 1 && full[8] == 1 && full[7] == 0)
  else if (full[6] == 1 && full[8] == 1 && full[7] == 0)
  {
  {
  full[7] = 2;
  full[7] = 2;
  matrix[2][1] = 'X';
  matrix[2][1] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[8] == 1 && full[7] == 1 && full[6] == 0)
  else if (full[8] == 1 && full[7] == 1 && full[6] == 0)
  {
  {
  full[6] = 2;
  full[6] = 2;
  matrix[2][0] = 'X';
  matrix[2][0] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[0] == 1 && full[3] == 1 && full[6] == 0)
  else if (full[0] == 1 && full[3] == 1 && full[6] == 0)
  {
  {
  full[6] = 2;
  full[6] = 2;
  matrix[2][0] = 'X';
  matrix[2][0] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[0] == 1 && full[6] == 1 && full[3] == 0)
  else if (full[0] == 1 && full[6] == 1 && full[3] == 0)
  {
  {
  full[3] = 2;
  full[3] = 2;
  matrix[1][0] = 'X';
  matrix[1][0] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[6] == 1 && full[3] == 1 && full[3] == 0)
  else if (full[6] == 1 && full[3] == 1 && full[3] == 0)
  {
  {
  full[3] = 2;
  full[3] = 2;
  matrix[0][0] = 'X';
  matrix[0][0] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[1] == 1 && full[4] == 1 && full[7] == 0)
  else if (full[1] == 1 && full[4] == 1 && full[7] == 0)
  {
  {
  full[7] = 2;
  full[7] = 2;
  matrix[2][1] = 'X';
  matrix[2][1] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[1] == 1 && full[7] == 1 && full[4] == 0)
  else if (full[1] == 1 && full[7] == 1 && full[4] == 0)
  {
  {
  full[4] = 2;
  full[4] = 2;
  matrix[1][1] = 'X';
  matrix[1][1] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[7] == 1 && full[4] == 1 && full[1] == 0)
  else if (full[7] == 1 && full[4] == 1 && full[1] == 0)
  {
  {
  full[1] = 2;
  full[1] = 2;
  matrix[0][1] = 'X';
  matrix[0][1] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[2] == 1 && full[5] == 1 && full[8] == 0)
  else if (full[2] == 1 && full[5] == 1 && full[8] == 0)
  {
  {
  full[8] = 2;
  full[8] = 2;
  matrix[2][2] = 'X';
  matrix[2][2] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[2] == 1 && full[8] == 1 && full[5] == 0)
  else if (full[2] == 1 && full[8] == 1 && full[5] == 0)
  {
  {
  full[5] = 2;
  full[5] = 2;
  matrix[1][2] = 'X';
  matrix[1][2] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[8] == 1 && full[5] == 1 && full[2] == 0)
  else if (full[8] == 1 && full[5] == 1 && full[2] == 0)
  {
  {
  full[2] = 2;
  full[2] = 2;
  matrix[0][2] = 'X';
  matrix[0][2] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[0] == 1 && full[4] == 1 && full[8] == 0)
  else if (full[0] == 1 && full[4] == 1 && full[8] == 0)
  {
  {
  full[8] = 2;
  full[8] = 2;
  matrix[2][2] = 'X';
  matrix[2][2] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[0] == 1 && full[8] == 1 && full[4] == 0)
  else if (full[0] == 1 && full[8] == 1 && full[4] == 0)
  {
  {
  full[4] = 2;
  full[4] = 2;
  matrix[1][1] = 'X';
  matrix[1][1] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[8] == 1 && full[4] == 1 && full[0] == 0)
  else if (full[8] == 1 && full[4] == 1 && full[0] == 0)
  {
  {
  full[0] = 2;
  full[0] = 2;
  matrix[0][0] = 'X';
  matrix[0][0] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[2] == 1 && full[4] == 1 && full[6] == 0)
  else if (full[2] == 1 && full[4] == 1 && full[6] == 0)
  {
  {
  full[8] = 2;
  full[8] = 2;
  matrix[2][0] = 'X';
  matrix[2][0] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[2] == 1 && full[6] == 1 && full[4] == 0)
  else if (full[2] == 1 && full[6] == 1 && full[4] == 0)
  {
  {
  full[8] = 2;
  full[8] = 2;
  matrix[1][1] = 'X';
  matrix[1][1] = 'X';
  return 1;
  return 1;
  }
  }
  else if (full[6] == 1 && full[4] == 1 && full[2] == 0)
  else if (full[6] == 1 && full[4] == 1 && full[2] == 0)
  {
  {
  full[2] = 2;
  full[2] = 2;
  matrix[0][2] = 'X';
  matrix[0][2] = 'X';
  return 1;
  return 1;
  }
  }
Line 960: Line 970:
[[새싹교실/2015]]
[[새싹교실/2015]]
[[새싹교실/2015/새벽반]]
[[새싹교실/2015/새벽반]]

Latest revision as of 00:45, 27 March 2026

참여자

강사 반페이지 학생
장우진 :새싹교실/2015/새벽반 /새벽반 박성훈 조원희 정창민
O O X


진행상황

  • 배열과 포인터에 대한 설명
  • 포인터를 가지고 연산 하기
  • call by reference?
  • call by value?
  • 질의응답

과제

  • 틱택토!!!
  • 마지막 과제입니다. 어려운거 해봅시다
  • 한 줄 빙고를 만들면 이기는 간단한 게임
  • 사용자와 컴퓨터가 대전
  • 선 플레이어 설정 기능과 난이도 설정 기능 구현
  • 간단한 GUI...

박성훈

#include <time.h>
#include <stdlib.h>

void playerturn();
void computerturn();
void hardcomputerturn();
int attack();
int protect();
int playerwin();
int computerwin();
int draw();
int full[9] = { 0, };
char matrix[3][3] = { '1', '2', '3', '4', '5', '6', '7', '8', '9' };


int main(){

	int a = 0;
	int first;
	int level;
	int levelfirst;
	int replay;

	srand((unsigned)time(NULL));

		
		printf("난이도를 골라주세요. 1.easy 2.hard\n");
		scanf("%d", &level);

		printf("누가 먼저 할껀가요? 1.사람 2. 컴퓨터\n");
		scanf("%d", &first);


		if (level == 1 && first == 1)
			levelfirst = 1;
		else if (level == 1 && first == 2)
			levelfirst = 2;
		else if (level == 2 && first == 1)
			levelfirst = 3;
		else
			levelfirst = 4;


		system("cls");

		for (;;){
			printf("┌─┬─┬─┐\n");
			printf("│%c │%c │%c │\n", matrix[0][0], matrix[0][1], matrix[0][2]);
			printf("├─┼─┼─┤\n");
			printf("│%c │%c │%c │\n", matrix[1][0], matrix[1][1], matrix[1][2]);
			printf("├─┼─┼─┤\n");
			printf("│%c │%c │%c │\n", matrix[2][0], matrix[2][1], matrix[2][2]);
			printf("└─┴─┴─┘\n");



			if (levelfirst == 1)
			{
				playerturn();
				levelfirst = 2;

			}

			else if (levelfirst == 2)
			{
				computerturn();
				levelfirst = 1;

			}


			else if (levelfirst == 3)
			{
				playerturn();
				levelfirst = 4;
			}

			else if (levelfirst == 4)
			{
				if (full[4] == 0)
				{
					matrix[1][1] = 'X';
					full[4] = 2;
					levelfirst = 3;
				}
				else
				{
					hardcomputerturn();
					levelfirst = 3;
				}

			}




			if (playerwin() == 1){
				system("cls");
				printf("┌─┬─┬─┐\n");
				printf("│%c │%c │%c │\n", matrix[0][0], matrix[0][1], matrix[0][2]);
				printf("├─┼─┼─┤\n");
				printf("│%c │%c │%c │\n", matrix[1][0], matrix[1][1], matrix[1][2]);
				printf("├─┼─┼─┤\n");
				printf("│%c │%c │%c │\n", matrix[2][0], matrix[2][1], matrix[2][2]);
				printf("└─┴─┴─┘\n");
				printf("YOU WIN!!!\n");
				break;
			}
			if (computerwin() == 1){
				system("cls");
				printf("┌─┬─┬─┐\n");
				printf("│%c │%c │%c │\n", matrix[0][0], matrix[0][1], matrix[0][2]);
				printf("├─┼─┼─┤\n");
				printf("│%c │%c │%c │\n", matrix[1][0], matrix[1][1], matrix[1][2]);
				printf("├─┼─┼─┤\n");
				printf("│%c │%c │%c │\n", matrix[2][0], matrix[2][1], matrix[2][2]);
				printf("└─┴─┴─┘\n");
				printf("You lose...\n");
				break;
			}
			if (draw() == 1){
				system("cls");
				printf("┌─┬─┬─┐\n");
				printf("│%c │%c │%c │\n", matrix[0][0], matrix[0][1], matrix[0][2]);
				printf("├─┼─┼─┤\n");
				printf("│%c │%c │%c │\n", matrix[1][0], matrix[1][1], matrix[1][2]);
				printf("├─┼─┼─┤\n");
				printf("│%c │%c │%c │\n", matrix[2][0], matrix[2][1], matrix[2][2]);
				printf("└─┴─┴─┘\n");
				printf("Draw\n");
				break;
			}

			system("cls");
		}
		

		return 0;
	}


	void playerturn()
	{
		int place = 0;
		int playerturnfinish = 0;
		printf("번호를 고르시오.\n");

		for (; playerturnfinish != 1;){
			scanf("%d", &place);

			if (place == 1)
			{
				if (full[0] == 0)
				{
					matrix[0][0] = 'O';
					full[0] = 1;
					playerturnfinish = 1;
				}
				else if (full[0] == 1 || full[0] == 2)
				{
					printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
					continue;
				}
			}
			else if (place == 2)
			{
				if (full[1] == 0)
				{
					matrix[0][1] = 'O';
					full[1] = 1;
					playerturnfinish = 1;
				}
				else if (full[1] == 1 || full[1] == 2)
				{
					printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
					continue;
				}
			}
			else if (place == 3)
			{
				if (full[2] == 0)
				{
					matrix[0][2] = 'O';
					full[2] = 1;
					playerturnfinish = 1;
				}
				else if (full[2] == 1 || full[2] == 2)
				{
					printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
					continue;
				}
			}
			else if (place == 4)
			{
				if (full[3] == 0)
				{
					matrix[1][0] = 'O';
					full[3] = 1;
					playerturnfinish = 1;
				}
				else if (full[3] == 1 || full[3] == 2)
				{
					printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
					continue;
				}
			}
			else if (place == 5)
			{
				if (full[4] == 0)
				{
					matrix[1][1] = 'O';
					full[4] = 1;
					playerturnfinish = 1;
				}
				else if (full[4] == 1 || full[4] == 2)
				{
					printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
					continue;
				}
			}
			else if (place == 6)
			{
				if (full[5] == 0)
				{
					matrix[1][2] = 'O';
					full[5] = 1;
					playerturnfinish = 1;
				}
				else if (full[5] == 1 || full[5] == 2)
				{
					printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
					continue;
				}
			}
			else if (place == 7)
			{
				if (full[6] == 0)
				{
					matrix[2][0] = 'O';
					full[6] = 1;
					playerturnfinish = 1;
				}
				else if (full[6] == 1 || full[6] == 2)
				{
					printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
					continue;
				}
			}
			else if (place == 8)
			{
				if (full[7] == 0)
				{
					matrix[2][1] = 'O';
					full[7] = 1;
					playerturnfinish = 1;
				}
				else if (full[7] == 1 || full[7] == 2)
				{
					printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
					continue;
				}
			}
			else if (place == 9)
			{
				if (full[8] == 0)
				{
					matrix[2][2] = 'O';
					full[8] = 1;
					playerturnfinish = 1;
				}
				else if (full[8] == 1 || full[8] == 2)
				{
					printf("이미 기호가 존재합니다. 다른 번호를 눌러주세요.\n");
					continue;
				}
			}

		}
	}

	void computerturn()
	{
		int place = 0;
		int computerturnfinish = 0;
		

		for (; computerturnfinish != 1;){
			
			place = rand() % ((9 - 1) + 1)+1;

			if (place == 1)
			{
				if (full[0] == 0)
				{
					matrix[0][0] = 'X';
					full[0] = 2;
					computerturnfinish = 1;
				}
				else if (full[0] == 1 || full[0] == 2)
				{
					
					continue;
				}
			}
			else if (place == 2)
			{
				if (full[1] == 0)
				{
					matrix[0][1] = 'X';
					full[1] = 2;
					computerturnfinish = 1;
				}
				else if (full[1] == 1 || full[1] == 2)
				{
					continue;
				}
			}
			else if (place == 3)
			{
				if (full[2] == 0)
				{
					matrix[0][2] = 'X';
					full[2] = 2;
					computerturnfinish = 1;
				}
				else if (full[2] == 1 || full[2] == 2)
				{
					
					continue;
				}
			}
			else if (place == 4)
			{
				if (full[3] == 0)
				{
					matrix[1][0] = 'X';
					full[3] = 2;
					computerturnfinish = 1;
				}
				else if (full[3] == 1 || full[3] == 2)
				{
					
					continue;
				}
			}
			else if (place == 5)
			{
				if (full[4] == 0)
				{
					matrix[1][1] = 'X';
					full[4] = 2;
					computerturnfinish = 1;
				}
				else if (full[4] == 1 || full[4] == 2)
				{
					
					continue;
				}
			}
			else if (place == 6)
			{
				if (full[5] == 0)
				{
					matrix[1][2] = 'X';
					full[5] = 2;
					computerturnfinish = 1;
				}
				else if (full[5] == 1 || full[5] == 2)
				{
					
					continue;
				}
			}
			else if (place == 7)
			{
				if (full[6] == 0)
				{
					matrix[2][0] = 'X';
					full[6] = 2;
					computerturnfinish = 1;
				}
				else if (full[6] == 1 || full[6] == 2)
				{
					
					continue;
				}
			}
			else if (place == 8)
			{
				if (full[7] == 0)
				{
					matrix[2][1] = 'X';
					full[7] = 2;
					computerturnfinish = 1;
				}
				else if (full[7] == 1 || full[7] == 2)
				{
					
					continue;
				}
			}
			else if (place == 9)
			{
				if (full[8] == 0)
				{
					matrix[2][2] = 'X';
					full[8] = 2;
					computerturnfinish = 1;
				}
				else if (full[8] == 1 || full[8] == 2)
				{
					
					continue;
				}
			}

		}
	}

	int playerwin(){
		if (full[0] ==1 && full[1] ==1 && full[2] == 1)
			return 1;
		else if (full[3] == 1 && full[4] == 1 && full[5] == 1)
			return 1;
		else if (full[6] == 1 && full[7] == 1 && full[8] == 1)
			return 1;
		else if (full[0] == 1 && full[3] == 1 && full[6] == 1)
			return 1;
		else if (full[1] == 1 && full[4] == 1 && full[7] == 1)
			return 1;
		else if (full[2] == 1 && full[5] == 1 && full[8] == 1)
			return 1;
		else if (full[0] == 1 && full[4] == 1 && full[8] == 1)
			return 1;
		else if (full[2] == 1 && full[4] == 1 && full[6] == 1)
			return 1;

	}

	int computerwin(){
		if (full[0] == 2 && full[1] == 2 && full[2] == 2)
			return 1;
		else if (full[3] == 2 && full[4] == 2 && full[5] == 2)
			return 1;
		else if (full[6] == 2 && full[7] == 2 && full[8] == 2)
			return 1;
		else if (full[0] == 2 && full[3] == 2 && full[6] == 2)
			return 1;
		else if (full[1] == 2 && full[4] == 2 && full[7] == 2)
			return 1;
		else if (full[2] == 2 && full[5] == 2 && full[8] == 2)
			return 1;
		else if (full[0] == 2 && full[4] == 2 && full[8] == 2)
			return 1;
		else if (full[2] == 2 && full[4] == 2 && full[6] == 2)
			return 1;

	}

	int draw()
	{
		if (full[0] != 0 && full[1] != 0 && full[2] != 0 && full[3] != 0 && full[4] != 0 && full[5] != 0 && full[6] != 0 && full[7] != 0 && full[8] != 0)
		{
			return 1;
		}
	}

	void hardcomputerturn()
	{

		int place = 0;
		int computerturnfinish = 0;


		for (; computerturnfinish != 1;){

			place = rand() % ((9 - 1) + 1) + 1;
			
			if (attack() == 1)
			{
				computerturnfinish = 1;
				break;
			}
			else if (protect() == 1)
			{
				computerturnfinish = 1;
				break;
			}

					if (place == 1)
					{
						if (full[0] == 0)
						{
							matrix[0][0] = 'X';
							full[0] = 2;
							computerturnfinish = 1;
						}
						else if (full[0] == 1 || full[0] == 2)
						{

							continue;
						}
					}
					else if (place == 2)
					{
						if (full[1] == 0)
						{
							matrix[0][1] = 'X';
							full[1] = 2;
							computerturnfinish = 1;
						}
						else if (full[1] == 1 || full[1] == 2)
						{
							continue;
						}
					}
					else if (place == 3)
					{
						if (full[2] == 0)
						{
							matrix[0][2] = 'X';
							full[2] = 2;
							computerturnfinish = 1;
						}
						else if (full[2] == 1 || full[2] == 2)
						{

							continue;
						}
					}
					else if (place == 4)
					{
						if (full[3] == 0)
						{
							matrix[1][0] = 'X';
							full[3] = 2;
							computerturnfinish = 1;
						}
						else if (full[3] == 1 || full[3] == 2)
						{

							continue;
						}
					}
					else if (place == 5)
					{
						if (full[4] == 0)
						{
							matrix[1][1] = 'X';
							full[4] = 2;
							computerturnfinish = 1;
						}
						else if (full[4] == 1 || full[4] == 2)
						{

							continue;
						}
					}
					else if (place == 6)
					{
						if (full[5] == 0)
						{
							matrix[1][2] = 'X';
							full[5] = 2;
							computerturnfinish = 1;
						}
						else if (full[5] == 1 || full[5] == 2)
						{

							continue;
						}
					}
					else if (place == 7)
					{
						if (full[6] == 0)
						{
							matrix[2][0] = 'X';
							full[6] = 2;
							computerturnfinish = 1;
						}
						else if (full[6] == 1 || full[6] == 2)
						{

							continue;
						}
					}
					else if (place == 8)
					{
						if (full[7] == 0)
						{
							matrix[2][1] = 'X';
							full[7] = 2;
							computerturnfinish = 1;
						}
						else if (full[7] == 1 || full[7] == 2)
						{

							continue;
						}
					}
					else if (place == 9)
					{
						if (full[8] == 0)
						{
							matrix[2][2] = 'X';
							full[8] = 2;
							computerturnfinish = 1;
						}
						else if (full[8] == 1 || full[8] == 2)
						{

							continue;
						}
					}
				}
			

		}


	

	int attack()
	{
		if ((full[0] ==2 && full[1] ==2) &&full[2]==0)
		{
			full[2] = 2;
			matrix[0][2] = 'X';
			return 1;
		}
		else if ((full[0] == 2 && full[2] == 2) && full[1] == 0)
		{
			full[1] = 2;
			matrix[0][1] = 'X';
			return 1;
		}
		else if ((full[1] == 2 && full[2] == 2) && full[0] == 0)
		{
			full[0] = 2;
			matrix[0][0] = 'X';
			return 1;
		}
		else if ((full[3] == 2 && full[4] == 2) && full[5] == 0)
		{
			full[5] = 2;
			matrix[1][2] = 'X';
			return 1;
		}
		else if ((full[3] == 2 && full[5] == 2) && full[4] == 0)
		{
			full[4] = 2;
			matrix[1][1] = 'X';
			return 1;
		}
		else if ((full[5] == 2 && full[4] == 2) && full[3] == 0)
		{
			full[3] = 2;
			matrix[1][0] = 'X';
			return 1;
		}
		else if ((full[6] == 2 && full[7] == 2) && full[8] == 0)
		{
			full[8] = 2;
			matrix[2][2] = 'X';
			return 1;
		}
		else if ((full[6] == 2 && full[8] == 2) && full[7] == 0)
		{
			full[7] = 2;
			matrix[2][1] = 'X';
			return 1;
		}
		else if ((full[8] == 2 && full[7] == 2) && full[6] == 0)
		{
			full[6] = 2;
			matrix[2][0] = 'X';
			return 1;
		}
		else if ((full[0] == 2 && full[3] == 2) && full[6] == 0)
		{
			full[6] = 2;
			matrix[2][0] = 'X';
			return 1;
		}
		else if ((full[0] == 2 && full[6] == 2) && full[3] == 0)
		{
			full[3] = 2;
			matrix[1][0] = 'X';
			return 1;
		}
		else if ((full[6] == 2 && full[3] == 2) && full[3] == 0)
		{
			full[3] = 2;
			matrix[0][0] = 'X';
			return 1;
		}
		else if ((full[1] == 2 && full[4] == 2) && full[7] == 0)
		{
			full[7] = 2;
			matrix[2][1] = 'X';
			return 1;
		}
		else if ((full[1] == 2 && full[7] == 2) && full[4] == 0)
		{
			full[4] = 2;
			matrix[1][1] = 'X';
			return 1;
		}
		else if ((full[7] == 2 && full[4] == 2) && full[1] == 0)
		{
			full[1] = 2;
			matrix[0][1] = 'X';
			return 1;
		}
		else if ((full[2] == 2 && full[5] == 2) && full[8] == 0)
		{
			full[8] = 2;
			matrix[2][2] = 'X';
			return 1;
		}
		else if ((full[2] == 2 && full[8] == 2) && full[5] == 0)
		{
			full[5] = 2;
			matrix[1][2] = 'X';
			return 1;
		}
		else if ((full[8] == 2 && full[5] == 2) && full[2] == 0)
		{
			full[2] = 2;
			matrix[0][2] = 'X';
			return 1;
		}
		else if ((full[0] == 2 && full[4] == 2)&& full[8] == 0)
		{
			full[8] = 2;
			matrix[2][2] = 'X';
			return 1;
		}
		else if ((full[0] == 2 && full[8] == 2)&& full[4] == 0)
		{
			full[4] = 2;
			matrix[1][1] = 'X';
			return 1;
		}
		else if ((full[8] == 2 && full[4] == 2) && full[0] == 0)
		{
			full[0] = 2;
			matrix[0][0] = 'X';
			return 1;
		}
		else if ((full[2] == 2 && full[4] == 2) && full[6] == 0)
		{
			full[8] = 2;
			matrix[2][0] = 'X';
			return 1;
		}
		else if ((full[2] == 2 && full[6] == 2)&& full[4] == 0)
		{
			full[8] = 2;
			matrix[1][1] = 'X';
			return 1;
		}
		else if ((full[6] == 2 && full[4] == 2) && full[2] == 0)
		{
			full[2] = 2;
			matrix[0][2] = 'X';
			return 1;
		}
		else
		{
			return 0;
		}
	}
	int protect()
	{
		if (full[0] == 1 && full[1] == 1 && full[2] == 0)
		{
			full[2] = 2;
			matrix[0][2] = 'X';
			return 1;
		}
		else if (full[0] == 1 && full[2] == 1 && full[1] == 0)
		{
			full[1] = 2;
			matrix[0][1] = 'X';
			return 1;
		}
		else if (full[1] == 1 && full[2] == 1 && full[0] == 0)
		{
			full[0] = 2;
			matrix[0][0] = 'X';
			return 1;
		}
		else if (full[3] == 1 && full[4] == 1 && full[5] == 0)
		{
			full[5] = 2;
			matrix[1][2] = 'X';
			return 1;
		}
		else if (full[3] == 1 && full[5] == 1 && full[4] == 0)
		{
			full[4] = 2;
			matrix[1][1] = 'X';
			return 1;
		}
		else if (full[5] == 1 && full[4] == 1 && full[3] == 0)
		{
			full[3] = 2;
			matrix[1][0] = 'X';
			return 1;
		}
		else if (full[6] == 1 && full[7] == 1 && full[8] == 0)
		{
			full[8] = 2;
			matrix[2][2] = 'X';
			return 1;
		}
		else if (full[6] == 1 && full[8] == 1 && full[7] == 0)
		{
			full[7] = 2;
			matrix[2][1] = 'X';
			return 1;
		}
		else if (full[8] == 1 && full[7] == 1 && full[6] == 0)
		{
			full[6] = 2;
			matrix[2][0] = 'X';
			return 1;
		}
		else if (full[0] == 1 && full[3] == 1 && full[6] == 0)
		{
			full[6] = 2;
			matrix[2][0] = 'X';
			return 1;
		}
		else if (full[0] == 1 && full[6] == 1 && full[3] == 0)
		{
			full[3] = 2;
			matrix[1][0] = 'X';
			return 1;
		}
		else if (full[6] == 1 && full[3] == 1 && full[3] == 0)
		{
			full[3] = 2;
			matrix[0][0] = 'X';
			return 1;
		}
		else if (full[1] == 1 && full[4] == 1 && full[7] == 0)
		{
			full[7] = 2;
			matrix[2][1] = 'X';
			return 1;
		}
		else if (full[1] == 1 && full[7] == 1 && full[4] == 0)
		{
			full[4] = 2;
			matrix[1][1] = 'X';
			return 1;
		}
		else if (full[7] == 1 && full[4] == 1 && full[1] == 0)
		{
			full[1] = 2;
			matrix[0][1] = 'X';
			return 1;
		}
		else if (full[2] == 1 && full[5] == 1 && full[8] == 0)
		{
			full[8] = 2;
			matrix[2][2] = 'X';
			return 1;
		}
		else if (full[2] == 1 && full[8] == 1 && full[5] == 0)
		{
			full[5] = 2;
			matrix[1][2] = 'X';
			return 1;
		}
		else if (full[8] == 1 && full[5] == 1 && full[2] == 0)
		{
			full[2] = 2;
			matrix[0][2] = 'X';
			return 1;
		}
		else if (full[0] == 1 && full[4] == 1 && full[8] == 0)
		{
			full[8] = 2;
			matrix[2][2] = 'X';
			return 1;
		}
		else if (full[0] == 1 && full[8] == 1 && full[4] == 0)
		{
			full[4] = 2;
			matrix[1][1] = 'X';
			return 1;
		}
		else if (full[8] == 1 && full[4] == 1 && full[0] == 0)
		{
			full[0] = 2;
			matrix[0][0] = 'X';
			return 1;
		}
		else if (full[2] == 1 && full[4] == 1 && full[6] == 0)
		{
			full[8] = 2;
			matrix[2][0] = 'X';
			return 1;
		}
		else if (full[2] == 1 && full[6] == 1 && full[4] == 0)
		{
			full[8] = 2;
			matrix[1][1] = 'X';
			return 1;
		}
		else if (full[6] == 1 && full[4] == 1 && full[2] == 0)
		{
			full[2] = 2;
			matrix[0][2] = 'X';
			return 1;
		}
		else
		{
			return 0;
		}
	}

정창민

조원희


새싹교실/2015 새싹교실/2015/새벽반