• <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>

            學習心得(code)

            superlong@CoreCoder

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

            公告

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

            常用鏈接

            留言簿(4)

            我參與的團隊

            搜索

            •  

            最新隨筆

            最新評論

            • 1.?re: Poj 1279
            • 對于一個凹多邊形用叉積計算面積 后能根據結果的正負來判斷給的點集的時針方向?
            • --bsshanghai
            • 2.?re: Poj 3691
            • 你寫的這個get_fail() 好像并是真正的get_fail,也是說fail指向的串并不是當前結點的子串。為什么要這樣弄呢?
            • --acmer1183
            • 3.?re: HDU2295[未登錄]
            • 這個是IDA* 也就是迭代加深@ylfdrib
            • --superlong
            • 4.?re: HDU2295
            • 評論內容較長,點擊標題查看
            • --ylfdrib
            • 5.?re: HOJ 11482
            • 呵呵..把代碼發在這里很不錯..以后我也試試...百度的編輯器太爛了....
            • --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   是否繼續(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 閱讀(347) 評論(0)  編輯 收藏 引用
            久久久久久狠狠丁香| 久久人人爽人人澡人人高潮AV| 久久亚洲sm情趣捆绑调教| 品成人欧美大片久久国产欧美...| 一本久久久久久久| 国产精品久久久久乳精品爆| 97超级碰碰碰碰久久久久| 一本一本久久A久久综合精品 | 亚洲国产另类久久久精品小说| 久久免费国产精品| 丁香色欲久久久久久综合网| 久久久久久国产精品美女| 国产免费久久精品99re丫y| 性高朝久久久久久久久久| 伊人久久大香线蕉无码麻豆| 亚洲中文字幕久久精品无码APP | 亚洲国产成人久久综合野外| 精品国际久久久久999波多野| 久久精品视屏| 中文字幕日本人妻久久久免费 | 国产精品九九久久免费视频| 久久精品夜色噜噜亚洲A∨| 久久国产成人午夜AV影院| 91久久精品无码一区二区毛片| 日韩影院久久| 99久久国产综合精品五月天喷水| .精品久久久麻豆国产精品| 免费久久人人爽人人爽av| 久久久久久狠狠丁香| 日韩精品久久无码人妻中文字幕| 久久综合亚洲色HEZYO社区| 一本久久综合亚洲鲁鲁五月天| 欧美激情精品久久久久久久| 97久久超碰国产精品2021| 精品国产乱码久久久久久呢| 中文字幕亚洲综合久久菠萝蜜| 99久久精品国产一区二区三区| 久久久久亚洲av综合波多野结衣| 精品国产乱码久久久久久人妻| 久久午夜夜伦鲁鲁片免费无码影视| 99久久国产综合精品成人影院|