• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            學(xué)習(xí)心得(code)

            superlong@CoreCoder

              C++博客 :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
              74 Posts :: 0 Stories :: 5 Comments :: 0 Trackbacks

            公告

            文字可能放在http://blog.csdn.net/superlong100,此處存放代碼

            常用鏈接

            留言簿(4)

            我參與的團(tuán)隊

            搜索

            •  

            最新隨筆

            最新評論

            • 1.?re: Poj 1279
            • 對于一個凹多邊形用叉積計算面積 后能根據(jù)結(jié)果的正負(fù)來判斷給的點集的時針方向?
            • --bsshanghai
            • 2.?re: Poj 3691
            • 你寫的這個get_fail() 好像并是真正的get_fail,也是說fail指向的串并不是當(dāng)前結(jié)點的子串。為什么要這樣弄呢?
            • --acmer1183
            • 3.?re: HDU2295[未登錄]
            • 這個是IDA* 也就是迭代加深@ylfdrib
            • --superlong
            • 4.?re: HDU2295
            • 評論內(nèi)容較長,點擊標(biāo)題查看
            • --ylfdrib
            • 5.?re: HOJ 11482
            • 呵呵..把代碼發(fā)在這里很不錯..以后我也試試...百度的編輯器太爛了....
            • --csuft1

            閱讀排行榜

            評論排行榜

            #include <stdio.h>
            #include 
            <iostream>
            #include 
            <string.h>
            #include 
            <stdlib.h>
            #include 
            <conio.h>
            #include 
            <io.h>
            #define HIGHT 20
            #define WIGHT 80
            #define N 8
            #define BLACK 1
            #define WHITE 2
            #define BPOS 3
            #define WPOS 4
            #define SPACE 0
            #define LEFT 75
            #define UP 72
            #define RIGHT 77
            #define DOWN 80
            #define ESC 27
            using namespace std;

            struct nod {
                
            int x, y;
            }
            point;

            int black, white, first, continued, esc;
            int move[4][2= {{-10}{0-1}{10}{01}};//up left down right
            int map[N][N], tp[N][N]; // 0->NULL 1->black 2->white
            char mode[16][3= {"","","","","","","","",
                                
            "","","""  """""""""}
            ;

            void logo() {
                system(
            "cls");
                puts(
            "\t        _O_    黑  _____   白    _<>_    棋    ___  ");
                puts(
            "\t      /     \\     |     |      /      \\      /  _  \\");
                puts(
            "\t     |==/=\\==|    |[/_\\]|     |==\\==/==|    |  / \\  |");
                puts(
            "\t     |  O O  |    / O O \\     |   ><   |    |  |\"|  |");
                puts("\t      \\  V  /    /\\  -  /\\  ,-\\   ()   /-.   \\  X  /");
                puts(
            "\t                                                        ");
                puts(
            "\t      /`---'\\     /`---'\\   V( `-====-' )V   /`---'\\");
                puts(
            "\t      O'_:_`O     O'M|M`O   (_____:|_____)   O'_|_`O ");
                puts(
            "\t       -- --       -- --      ----  ----      -- -- ");
                puts(
            "\t                  請選擇先手                        \n\n"); 
                puts(
            "\t\t      1、    ●                  \n");
                puts(
            "\t\t      2、    ○        \n");
                puts(
            "\t\t      3、   退出     \n");    
                printf(
            "\t\t      您的選擇:"); 
                scanf(
            "%d"&first);
                
            if(first != 1 && first != 2 && first != 3) logo();
                
            }

                        
            void draw(char head[], char body[], char cross[], char tail[], int size, int row, int mp[N][N]) {
                printf(
            "%s", head);
                
            for(int i = 1; i < 2 * size; i ++{
                    
            if(i % 2 == 0{
                        printf(
            "%s", cross);
                    }
             else {
                        
            int t = (i + 1/ 2 - 1, r = row / 2 - 1;
                        
            if(row % 2 == 0 && ((i + 1% 2 == 0)) {
                            printf(
            "%s", mode[11 + mp[r][t]]);
                        }
             else {
                            printf(
            "%s", body);
                        }

                    }

                }

                printf(
            "%s\n", tail);    
            }


            void set_map(int size, int mp[N][N]) {
                
            int temp;
                system(
            "cls");
                temp 
            = (HIGHT - size) / 2;
                puts(
            "\n\t\t\t\t黑白棋");
                puts(
            "\t\t\t 用ENTER放置棋子  用ESC鍵退出\n"); 
                
            for(int i = 1; i <= 2 * size + 1; i ++{
                    temp 
            = (WIGHT - 2 * size + 1)  / 2 - 2 * size + 1;
                    
            for(int j = 0; j < temp; j ++) putchar(' ');
                    
            if(i == 1) draw(mode[0], mode[1], mode[2], mode[3], size, i, mp);
                    
            else if(i == 2 * size + 1) draw(mode[7], mode[1], mode[8], mode[9], size, i, mp);
                    
            else if(i % 2) draw(mode[4], mode[1], mode[5], mode[6], size, i, mp);
                    
            else           draw(mode[10], mode[11], mode[10], mode[10], size, i, mp);
                }

                printf(
            "\n\t記分牌:    ○:%d               \t ●:%d\n", white, black);
            }


            void init() {
                memset(map, 
            0sizeof(map));
                map[
            3][3= map[4][4= BLACK;
                map[
            4][3= map[3][4= WHITE;
                
            //map[0][0] = WHITE;
                
            //map[1][0] = BLACK;
                
            //map[0][1] = BLACK;
                point.x = point.y = 0;
                black 
            = 2;
                white 
            = 2;
                set_map(
            8, map);    
            }


            int move8[8][2= {{01}{10}{0-1}{-10},
                               
            {11}{1-1}{-11}{-1-1}}
            ;

            bool inmap(int x, int y) {
                
            if(x < 0 || y < 0 || x >= N || y >= N) return false;
                
            return true;
            }


            bool judge(int x, int y, int col, int mp[N][N]) {
                
            if(mp[x][y] == WHITE || mp[x][y] == BLACK) return false;
                
            for(int dic = 0; dic < 8; dic ++{
                    
            int tx = x + move8[dic][0], ty = y + move8[dic][1], flag = 0;
                    
            while(mp[tx][ty] == 3 - col && inmap(tx, ty)) {
                        tx 
            += move8[dic][0]; 
                        ty 
            += move8[dic][1];
                        flag 
            = 1;
                    }

                    
            if(!flag) continue;
                    
            if( inmap(tx, ty) ) {
                        
            if(mp[tx][ty] == col) return true;
                    }

                }

                
            return false;
            }


            void change(int x, int y, int col, int mp[N][N]) {
                
            for(int dic = 0; dic < 8; dic ++{
                    
            int tx = x + move8[dic][0], ty = y + move8[dic][1], flag = 0;
                    
            while(mp[tx][ty] == 3 - col && inmap(tx, ty)) {
                        tx 
            += move8[dic][0]; 
                        ty 
            += move8[dic][1];
                        flag 
            = 1;
                    }

                    
            if(!flag) continue;
                    
            if( inmap(tx, ty) ) {
                        
            if(mp[tx][ty] == col) {
                            
            int xx = x, yy = y;
                            
            while(xx != tx || yy != ty) {
                                mp[xx][yy] 
            = col;
                                xx 
            += move8[dic][0];
                                yy 
            += move8[dic][1];
                            }

                        }

                    }

                }

            }


            void calc(int mp[N][N]) {
                white 
            = black = 0;
                
            for(int i = 0; i < N; i ++)
                    
            for(int j = 0; j < N; j ++{
                        
            if(mp[i][j] == WHITE) white ++;
                        
            if(mp[i][j] == BLACK) black ++;
                    }

            }


            bool isok(int col, int mp[N][N]) {
                
            for(int i = 0; i < N; i ++{
                    
            for(int j = 0; j < N; j ++{
                        
            if( judge(i, j, col, mp) ) return true;
                    }

                }

                
            return false;
            }

            void GameOver() {
                system(
            "cls");
                cout 
            << "\t\t\t\t黑白棋\n\n" << endl;
                cout 
            << "\t\t※※※※※※※※※※※※※※※※※※※※※" << endl;
                cout 
            << "\t\t※                                      ※" << endl;
                cout 
            << "\t\t※                                      ※" << endl;
                cout 
            << "\t\t※                                      ※" << endl;
                cout 
            << "\t\t※                                      ※" << endl;
                cout 
            << "\t\t※";
                cout 
            <<"            GAME     OVER             ";
                cout 
            << "" << endl;
                cout 
            << "\t\t※                                      ※" << endl;
                cout 
            << "\t\t※            ";
                printf( 
            "●:%2d     ○:%2d           ※\n",white, black); ;
                cout 
            << "\t\t※                                      ※" << endl;
                cout 
            << "\t\t※                                      ※" << endl;
                
            if( black < white) {
                cout 
            << "\t\t※          ●    wins!                 ※" << endl;
                }
             else if( black > white) {
                cout 
            << "\t\t※          ○    wins!                 ※" << endl;
                }
             else {
                cout 
            << "\t\t※            TIE                       ※" << endl;
                }

                cout 
            << "\t\t※                                      ※" << endl;
                cout 
            << "\t\t※                                      ※" << endl;
                cout 
            << "\t\t※                                      ※" << endl;
                cout 
            << "\t\t※                                      ※" << endl;
                cout 
            << "\t\t※※※※※※※※※※※※※※※※※※※※※" << endl;
                cout 
            << endl << endl;
            }

            void final() {
                GameOver();
                printf( 
            "\t\t   是否繼續(xù)(Y/N):   ");
                
            char ss[2];
                scanf(
            "%s", ss);
                
            if(ss[0== 'Y'{
                    system(
            "pause");
                    
            return;
                }
             else {
                    esc 
            = 1;
                    
            return;
                }

            }


            void play() {
                
            int player = 2 + first;
                
            int last = map[0][0];
                
            while(true{
                    
            int flag = 0;
                    map[point.x][point.y] 
            = last;
                    set_map(
            8, map);
                    
            if!isok(player - 2, map) && !isok(5 - player, map) )  {
                        
                        final();
                        
            return;
                    }
             else 
                    
            if!isok(player - 2, map) ) {
                        flag 
            = 1;
                        player 
            = 7 - player;
                    }

                    map[
            0][0= player;
                    set_map(
            8, map);
                    
            if(flag) {
                        printf(
            "本方無棋可走,更換棋手\n"); 
                    }

                    
            char keyborad;
                    
            while( (keyborad = getch()) != '\x0d'{
                        keyborad 
            = getch();
                        
            if(keyborad == ESC) {
                            esc 
            = 1;
                            
            return;
                        }

                        
            int dic;
                        
            switch(keyborad) {
                            
            case UP:
                                dic 
            = 0;
                                
            break;
                            
            case LEFT:
                                dic 
            = 1;
                                
            break;
                            
            case DOWN:
                                dic 
            = 2;
                                
            break;
                            
            case RIGHT:
                                dic 
            = 3;
                                
            break;
                            
            default:
                                keyborad 
            = getch();
                                
            continue;
                        }

                        
            int tx = (point.x + N + move[dic][0]) % N, ty = (point.y + N + move[dic][1]) % N;
                        map[point.x][point.y] 
            = last;
                        point.x 
            = tx;
                        point.y 
            = ty;
                        last 
            = map[point.x][point.y];
                        map[point.x][point.y] 
            = player;
                        set_map(
            8, map);
                    }

                    
            if( judge(point.x, point.y, player - 2, map) && last == SPACE) {
                        map[point.x][point.y] 
            = player - 2;
                        change(point.x, point.y, player 
            - 2, map);
                        calc(map);
                        player 
            = 3 + WPOS - player;
                        point.x 
            = point.y = 0;
                        last 
            = map[0][0];
                        map[
            0][0= player;
                        set_map(
            8, map);
                    }
             else {
                        set_map(
            8, map); 
                        puts(
            "\t       \t       \t  該位置不能放置"); 
                        system(
            "pause");
                        map[point.x][point.y] 
            = last;
                        last 
            = map[0][0];
                        point.x 
            = point.y = 0;
                    }

                }

            }


            int main() {
                logo();
                
            if(first == 3return 0;
                continued 
            = 1; esc = 0;
                
            while(continued && !esc) {
                    init();
                    play();
                }

            }

            posted on 2009-11-10 11:33 superlong 閱讀(349) 評論(0)  編輯 收藏 引用

            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            久久丝袜精品中文字幕| 国产精品久久精品| 人妻无码精品久久亚瑟影视| 日本久久中文字幕| 久久天天躁狠狠躁夜夜躁2O2O | 久久人爽人人爽人人片AV| 久久久无码精品亚洲日韩按摩| 69国产成人综合久久精品| 日本道色综合久久影院| 国产香蕉久久精品综合网| 久久精品国产亚洲AV大全| 四虎国产精品免费久久5151| 午夜精品久久久久成人| 精品久久久噜噜噜久久久| 久久精品国产72国产精福利| 久久久亚洲欧洲日产国码二区| 久久av高潮av无码av喷吹| 精品人妻久久久久久888| 久久综合一区二区无码| 精品久久香蕉国产线看观看亚洲 | AAA级久久久精品无码片| 久久人人爽人人爽AV片| 精品久久久无码人妻中文字幕豆芽| 99热都是精品久久久久久| 久久久久久久亚洲Av无码| 一本一本久久a久久精品综合麻豆| 久久久中文字幕| 久久国产精品成人影院| 久久频这里精品99香蕉久| 国产成人精品久久综合| 久久99精品国产99久久6男男| 亚洲午夜久久久久妓女影院| 伊人久久无码精品中文字幕| 日本免费久久久久久久网站| 97精品国产91久久久久久| 日韩AV无码久久一区二区| 波多野结衣AV无码久久一区| 久久人妻少妇嫩草AV蜜桃| 久久综合亚洲色HEZYO社区| 久久久久久国产精品美女 | 亚洲国产成人久久精品动漫|