반응형
    
    
    
  Console로 프로그래밍된 바둑 소스이다.
출처는 불분명... 어디더라??
 
                    
        출처는 불분명... 어디더라??
- #include <stdio.h>
 - #include <windows.h>
 - #include <stdlib.h>
 - #include <conio.h>
 - #define LEFT '4'
 - #define RIGHT '6'
 - #define UP '8'
 - #define DOWN '2'
 - #define ENTER '5'
 - #define CLEAR 0
 - #define NONE 0
 - #define MAPSIZE 19
 - #define PLAYER1 1
 - #define PLAYER2 2
 - #define PLAY 1
 - #define START 1
 - #define END 0
 - #define NO 0
 - #define OK 1
 - #define YES 1
 - #define OKTOTALCOUNT 4
 - #define FLAGTRUE 1
 - #define FLAGFALSE 0
 - void gotoxy(int x, int y);
 - int xy[MAPSIZE][MAPSIZE];
 - int map[MAPSIZE][MAPSIZE];
 - int x, y, x2 = 2;
 - int centerX=MAPSIZE/2, centerY=MAPSIZE/2;
 - int displayX=0, displayLineY=21, displayY=22;
 - char mapChar[]="┌┬┐├┼┤└┴┘";
 - void clearValue() {
 - int x,y;
 - for(y=0;y<MAPSIZE;y++) {
 - for(x=0;x<MAPSIZE;x++) {
 - map[y][x]=CLEAR;
 - }
 - }
 - }
 - int IsKill(int cnt) {
 - return cnt==OKTOTALCOUNT;
 - }
 - int TestFlag(int x,int y) {
 - if(x<0 x>=MAPSIZE y<0 y>=MAPSIZE) return FLAGTRUE;
 - if(map[y][x]==OK) return FLAGTRUE;
 - return FLAGFALSE;
 - }
 - int SefeDeleteTest(int x,int y,int OtherPlayer) {
 - int result;
 - int cnt;
 - if(x<0 x>=MAPSIZE y<0 y>=MAPSIZE) return OK;
 - if(xy[y][x]==OtherPlayer) return OK;
 - if(xy[y][x]==NONE) return NO;
 - cnt=0;
 - result=NO;
 - map[y][x]=OK;
 - if(TestFlag(x,y-1)==FLAGFALSE) {
 - if(SefeDeleteTest(x,y-1,OtherPlayer)) {
 - cnt=cnt + 1;
 - }
 - } else {
 - cnt=cnt+1;
 - }
 - if(TestFlag(x-1,y)==FLAGFALSE) {
 - if(SefeDeleteTest(x-1,y,OtherPlayer)) {
 - cnt=cnt + 1;
 - }
 - } else {
 - cnt=cnt+1;
 - }
 - if(TestFlag(x+1,y)==FLAGFALSE) {
 - if(SefeDeleteTest(x+1,y,OtherPlayer)) {
 - cnt=cnt + 1;
 - }
 - } else {
 - cnt=cnt+1;
 - }
 - if(TestFlag(x,y+1)==FLAGFALSE) {
 - if(SefeDeleteTest(x,y+1,OtherPlayer)) {
 - cnt=cnt + 1;
 - }
 - } else {
 - cnt=cnt+1;
 - }
 - if(IsKill(cnt)){
 - result=OK;
 - }
 - return result;
 - }
 - void DolDelete(int x,int y,int OtherPlayer) {
 - if(x<0 x>=MAPSIZE y<0 y>=MAPSIZE) return;
 - if(xy[y][x]==OtherPlayer) return;
 - if(xy[y][x]==NONE) return;
 - xy[y][x]=CLEAR;
 - if(x+1<MAPSIZE) DolDelete(x+1,y,OtherPlayer);
 - if(x-1>=0) DolDelete(x-1,y,OtherPlayer);
 - if(y+1<MAPSIZE) DolDelete(x,y+1,OtherPlayer);
 - if(y-1>=0) DolDelete(x,y-1,OtherPlayer);
 - }
 - void RalDeleteTest(int x,int y,int OtherPlayer) {
 - clearValue();
 - if(SefeDeleteTest(x+1,y,OtherPlayer)==YES)
 - DolDelete(x+1,y,OtherPlayer);
 - clearValue();
 - if(SefeDeleteTest(x-1,y,OtherPlayer)==YES)
 - DolDelete(x-1,y,OtherPlayer);
 - clearValue();
 - if(SefeDeleteTest(x,y+1,OtherPlayer)==YES)
 - DolDelete(x,y+1,OtherPlayer);
 - clearValue();
 - if(SefeDeleteTest(x,y-1,OtherPlayer)==YES)
 - DolDelete(x,y-1,OtherPlayer);
 - }
 - void input(int Player) {
 - char c;
 - int LOOP=START;
 - int OtherPlayer;
 - if(Player == PLAYER1) {
 - OtherPlayer = PLAYER2;
 - } else {
 - OtherPlayer = PLAYER1;
 - }
 - while(LOOP!=END){
 - c = getch();
 - switch(c)
 - {
 - case RIGHT:
 - x=x+1;
 - if(x >= MAPSIZE) x=x-1;
 - gotoxy(x,y);
 - break;
 - case LEFT:
 - x=x-1;
 - if(x < 0 ) x=x+1;
 - gotoxy(x,y);
 - break;
 - case UP:
 - y=y-1;
 - if(y < 0 ) y=y+1;
 - gotoxy(x,y);
 - break;
 - case DOWN:
 - y=y+1;
 - if(y >= MAPSIZE ) y=y-1;
 - gotoxy(x,y);
 - break;
 - case ENTER:
 - if(xy[y][x] != NONE ) break;
 - xy[y][x]=Player;
 - RalDeleteTest(x,y,Player);
 - clearValue();
 - if(SefeDeleteTest(x,y,OtherPlayer)==YES){
 - xy[y][x]=CLEAR;
 - } else {
 - LOOP = END;
 - }
 - }
 - }
 - }
 - void printScreen(){
 - system("cls");
 - int x,y,n;
 - char c[3];
 - for(y=0;y<MAPSIZE;y++) {
 - for(x=0;x<MAPSIZE;x++) {
 - if(xy[y][x] == PLAYER1) {
 - } else if(xy[y][x] == PLAYER2 ) {
 - } else if(xy[y][x] == NONE ) {
 - n=(x+16)/17+(y+16)/17*3;
 - c[0]=mapChar[n*2];
 - c[1]=mapChar[n*2+1];
 - c[2]=0;
 - if((x-3)%6==0 && (y-3)%6==0) {
 - strcpy(c,"×");
 - }
 - }
 - }
 - }
 - gotoxy(displayX,displayLineY);
 - }
 - int gamePlayCheck(int Player)
 - {
 - //승패를 가른다.
 - return 1;
 - }
 - void InitMapData() {
 - int x,y;
 - for(y=0;y<MAPSIZE;y++) {
 - for(x=0;x<MAPSIZE;x++) {
 - xy[y][x]=CLEAR;
 - }
 - }
 - }
 - // 커서를 나타냅니다.
 - void SetCursorShow(void)
 - {
 - HANDLE hConsole;
 - hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
 - CONSOLE_CURSOR_INFO ci;
 - GetConsoleCursorInfo( hConsole, &ci );
 - ci.dwSize=100;
 - ci.bVisible = TRUE;
 - SetConsoleCursorInfo( hConsole , &ci );
 - }
 - void main() {
 - int Player=PLAYER1,GamePlayFlag=PLAY;
 - InitMapData();
 - SetCursorShow();
 - clearValue();
 - printScreen();
 - x=centerX;
 - y=centerY;
 - while(GamePlayFlag!=END){
 - gotoxy(displayX,displayY);
 - gotoxy(x,y);
 - input(Player);
 - printScreen();
 - if(Player==PLAYER1) {
 - Player=PLAYER2;
 - } else {
 - Player=PLAYER1;
 - }
 - GamePlayFlag = gamePlayCheck(Player);
 - }
 - gotoxy(displayX,displayY);
 - }
 - void gotoxy(int x , int y)
 - {
 - COORD Pos = { x*2 , y};
 - SetConsoleCursorPosition(GetStdHandle( STD_OUTPUT_HANDLE), Pos);
 - }
 
반응형
    
    
    
  'Computer_IT > C++' 카테고리의 다른 글
| LinkedList 자료 (0) | 2006.04.06 | 
|---|---|
| VC++ 단축키 모음 (2) | 2006.03.19 | 
| Console Codepage 설정. (0) | 2006.02.15 | 
| [펌] Visual C++ Console - 사격게임 (0) | 2006.02.15 | 
| Visual C++ Console 에서 TurboC clrscr 구현 (0) | 2006.02.15 |