简约设计の艺术

讨论软件制造过程中的艺术与工程,软件哲学

用户操作
[即时聊天] [发私信] [加为好友]
丁亮ID:DL88250
1770534次访问,排名10,好友401人,关注者486人。
软件设计师,网络ID:88250,Linux、Open Source 热爱者,擅长JavaSE/JavaEE开发,熟悉JSF、EJB、Spring、Seam、OSGi等框架应用的架构,目前正在深入学习OOAD与敏捷过程。
DL88250的文章
原创 883 篇
翻译 14 篇
转载 195 篇
评论 821 篇
丁亮的公告




网络资源推荐:
  1. 海量IT培训视频免费下载:www.ibeifeng.com
最近评论
czlt86:呵呵,这节目我也看了,真是可笑,大人们天天玩麻将还有人玩的妻离子散的,干什么事都有人会走极端,央视就只拿这些人说事,游戏根本不是这样,想当初正是因为游戏才让我一步踏进了神奇的计算机世界,爱上它并扬言要一辈子搞计算机,也正是因为《仙剑》才给了我最初对中国的传统文化(诗词,服饰,建筑,侠,义,情.....)最直观的感受,并流连忘返,而现在,在中国主流媒体的“引导”下(应该还有万恶的审批制度),上……
管理人:エッチアダルト出会い
haha652:请教一下如果是manytomany除了2个主键以外,我还需要其他属性,能举个例子吗?谢谢~~~~
haha652:GOOD JOB!
ilyz5609:太帅了,关于SWT的参考资料可以在哪里找到?
文章分类
收藏
    相册
    Beyond
    壁纸收集
    动漫Kiss图图
    我的珍藏
    我的桌面
    Code snips
    C++代码示例
    HTML代码示例
    Java Code examples
    CSDN experts
    孟岩的专栏
    袁萌的专栏
    E-books
    CSDN下载频道
    e 书时空
    IT e Book
    中华电脑书库
    中国 E 书网
    中国 IT 认证实验室
    中文电子书网
    偶要雷锋 - 分享社区
    我爱 e 书
    网络中国 - E 书
    Linux/Ubuntu
    ChinaUnix
    Compiz Themes
    Compiz-Fusion
    deviantART Search
    GetDeb
    Gnome-Look
    KDE-Look
    LinuxToy
    Linux桌面中文网
    Ubuntu中文官方论坛
    Ubuntu桌面中文网
    My friends
    Eleven的专栏
    Eric.Gao的空间
    Meteor的专栏
    mmchsusan的主页
    solonote的专栏
    Vanessa的小窝
    ZhiBaoDeng的专栏
    zyofprogrammer的学习历程
    先知罗庄的专栏
    光光的Blog~
    师傅dorainm的Blog
    皮皮的空间
    秋歌的专栏
    金秋风采
    阿明的专栏
    My Projects
    BeyondTrack
    LivaPlayer
    YOYOPlayer
    Super stars :-)
    Alan Turing
    Bjarne Stroustrup's Homepage
    Don Knuth's Home Page
    Martin Fowler
    Richard Stallman's Home Page
    Uncle Bob (Robert C. Martin)
    Technologies
    Apache Software
    CSDN
    Eclipse.org
    Extreme Programming
    Facelets DevDoc
    hibernate.org
    IBM软件技术
    JavaEye
    JavaFX Home
    JavaFX Script Reference
    java-source
    JavaWorld@TW
    Java开源大全
    JBoss.org
    LEX & YACC Page
    NetBeans中文社区
    Open Source Initiative
    PHP 官方
    Ruby on Rails
    Ruby中文社区论坛
    SOURCEFORGE.NET
    Springframework.org
    Struts Framework
    Sun中国技术社区
    Testng.org
    UML官方
    水族馆(Aquarium 中文版)
    存档
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 C语言实现的井字棋收藏

    新一篇: C实现缓冲区溢出 | 旧一篇: C语言实现SMTP协议发送邮件

    /* 
    *  文件名:#.c
    *  用途:井字棋程序
    *  编程环境:WinXP SP2+CL 8.0
    *  完成日期: 2006.8   Ver 0.01
    *  作者: 88250
    *  联系方式: E-mail: DL88250@gmail.com  QQ:845765
    */

    #include 
    <stdio.h>

    #define P1 1

    #define P2 -1

    #define SIZE 3

    #define WIN -1

    #define UNWIN 0

    #define PEACE 1

    #define chkAndPutDwnRow(row, col){

                
    for(col = 0; col < SIZE; col++){

                    
    if(chsman[row][col] == 0){

                        chsman[row][col] 
    = P2;

                        dsply();

                        
    return;

                    }

                }

            }

    #define chkAndPutDwnCol(row, col){

                
    for(col = 0; col < SIZE; col++){

                    
    if(chsman[col][row] == 0){

                        chsman[col][row] 
    = P2;

                        dsply();

                        
    return;

                    }

                }

            }

    #define chkAndPutDwn_Slsh(row, col){

                
    if(chsman[row][col] == 0){

                    chsman[row][col] 
    = P2;

                    dsply();

                    
    return;

                }

            }    

    int chsman[SIZE][SIZE] = {0};

    /*function prototype (declaration).*/

    int enterChsman(intint);

    void dsply(void);

    void input(void);

    void judge(void);

    int chkWin(void);

    int chkPeace(void);

    /*create a global variable named stepFlg use to note the step.*/

    int stepFlg = 0;



    int enterChsman(int row, int col)

    {

        
    /*out of size.*/

        
    if(row >= SIZE || col >= SIZE)

            
    return 0;

        
    /*the pionted location is not empty.*/

        
    if(chsman[row][col] != 0)

            
    return 0;

        
    /*okay, put down the chessman.*/

        chsman[row][col] 
    = P1;

        
    return 1;

    }

    /*user input.*/

    void input(void)

    {

        
    int row, col;

        
    do{

            printf(
    "Please locate your chessman: ");

            printf(
    "Location row: ");

            scanf(
    "%d"&row);

            printf(
    "Location column: ");

            scanf(
    "%d"&col);

            
    if(enterChsman(row - 1, col - 1== 1){

                printf(
    "You located chessman at [%d][%d]. ", row, col);

                dsply();

                
    break;

            }

            
    else

                printf(
    "Error : You put the chess to a wrong location ");

        }
    while(1);

        
    return;

    }

    /*computer judge and input.*/

    void judge(void)

    {

        
    int row, col;

        
    int i;

        
    /*the risk level status of the chessboard.*/

        
    /*the attack level status of the chessboard.*/

        
    int rskAndAtkLevlRow[SIZE] = {0}, rskAndAtkLevlCol[SIZE] = {0}, rskAndAtkLevlSlsh[2= {0};

        
    /*obviate the special satus of the first chessman */

        
    if(stepFlg == 0){

            
    /*now, flag the first chessman had down.*/

            stepFlg 
    = 1;

            
    if(chsman[1][1== P1){

                chsman[
    0][0= P2;

                printf(
    "The computer located chessman at [1][1]. ");

                dsply();

                
    return;

            }    

            
    else{

                chsman[
    1][1= P2;

                printf(
    "The computer located chessman at [2][2]. ");

                dsply();

                
    return;

            }

        }

        
    /*note the number of the step.*/

        stepFlg
    ++;

        
    if(stepFlg == 2){

            
    if((chsman[0][0== P1 && chsman[2][2== P1) || (chsman[0][2== P1 && chsman[2][0== P1)){

                chsman[
    0][1= P2;

                printf(
    "The computer located chessman at [1][2]. ");

                dsply();

                
    return;

            }

        }

        
    /*evaluate the risk level and attack level of every row, column and slash.*/

        
    for(row = 0; row < SIZE; row++){

            
    for(col = 0; col < SIZE; col++){

                rskAndAtkLevlRow[row] 
    += chsman[row][col];

            }

        }

        
    for(col = 0; col < SIZE; col++){

            
    for(row = 0; row < SIZE; row++){

                rskAndAtkLevlCol[col] 
    += chsman[row][col];

            }

        }

        rskAndAtkLevlSlsh[
    0= chsman[0][0+ chsman[1][1+ chsman[2][2];

        rskAndAtkLevlSlsh[
    1= chsman[0][2+ chsman[1][1+ chsman[2][0];

        
    /*attck!*/

        
    /*attck a row.*/

        
    for(i = 0; i < SIZE; i++){

            
    if(rskAndAtkLevlRow[i] == -2){

                chkAndPutDwnRow(i, col)

            }

        }

        
    /*attck a column.*/

        
    for(i = 0; i< SIZE; i++){

            
    if(rskAndAtkLevlCol[i] == -2){

                chkAndPutDwnCol(i, col)

            }

        }

        
    /*attack slash().*/

        
    if(rskAndAtkLevlSlsh[0== -2){

            
    for(row = 0, col = 0; row < SIZE; row++, col++){

                chkAndPutDwn_Slsh(row, col)

            }

        }

        
    /*attack slash(/).*/

        
    if(rskAndAtkLevlSlsh[1== -2){

            
    for(row = 0, col = 2; row < SIZE; row++, col--){

                chkAndPutDwn_Slsh(row, col)

            }

        }

        
    /*locate the risk grid and put down one chessman to resolve it.*/

        
    /*resolve the risk of a Row.*/

        
    for(i = 0; i < SIZE; i++){

            
    if(rskAndAtkLevlRow[i] == 2){

                chkAndPutDwnRow(i, col)

            }

        }

        
    /*resolve the risk of a column.*/

        
    for(i = 0; i< SIZE; i++){

            
    if(rskAndAtkLevlCol[i] == 2){

                chkAndPutDwnCol(i, col)

            }

        }

        
    /*resolve the risk of a slash().*/

        
    if(rskAndAtkLevlSlsh[0== 2){

            
    for(row = 0, col = 0; row < SIZE; row++, col++){

                chkAndPutDwn_Slsh(row, col)

            }

        }

        
    /*resolve the risk of a slash(/).*/

        
    if(rskAndAtkLevlSlsh[1== 2){

            
    for(row = 0, col = 2; row < SIZE; row++, col--){

                chkAndPutDwn_Slsh(row, col)

            }

        }

        
    /*if there is no risk exist, put down the chessman in a blank(is not the best blank, may be).*/

        
    for(row = 0; row < SIZE; row++){

            
    for(col = 0; col < SIZE; col++){

                
    if(chsman[row][col] == 0 && ((row == 0 && col == 0|| (row == 0 && col == 2||

                    (row 
    == 2 && col == 0|| (row == 2 && col == 2))){

                    chsman[row][col] 
    = P2;

                    dsply();

                    
    return;

                }

            }

        }

    }

    /*display the current chessman board.*/

    void dsply(void)

    {

        
    int row, col, i;

           
    /*print the head.*/

        
    for(i = 0; i < SIZE * 4 + 1; i++)

            printf(
    "-");

        printf(
    " ");

        
    /*print the contect.*/

        
    for(row = 0; row < SIZE; row++){

            printf(
    "|");

            
    for(col = 0; col < SIZE; col++){    

                
    if(chsman[row][col] == P1)    printf(" o |");

                
    else if(chsman[row][col] == P2)    printf(" x |");

                
    else printf("   |");

            }

            printf(
    " ");

            
    /*print the floor.*/

            
    for(i = 0; i < SIZE * 4 + 1; i++)

                printf(
    "-");

            printf(
    " ");

        }

        
    return;

    }

    /*check whether win this game.*/

    int chkWin(void)

    {

        
    int i;

        
    for(i = 0; i < SIZE; i++){

            
    if(chsman[i][0+ chsman[i][1+ chsman[i][2== -3 || chsman[0][i] + chsman[1][i] + chsman[2][i] == -3 ||

                chsman[
    0][0+ chsman[1][1+ chsman[2][2== -3 || chsman[0][2+ chsman[1][1+ chsman[2][0== -3){

                
    return WIN;

            }

        }

        
    return UNWIN;

    }

    /*check whether peace with user.*/

    int chkPeace(void)

    {

        
    int row, col;

        
    int sum = 0;

        
    for(row = 0; row < SIZE; row++){

            
    for(col = 0; col < SIZE; col++){

                
    if(sum += chsman[row][col] == PEACE){

                    
    return PEACE;

                }

            }

        }

        
    return 0;

    }

    int main(char* args[])

    {

        
    /*display the chess board.*/

        dsply();

        
    do{

            
    /*user's turn of input.*/

            input();

            
    /*computer says: it is my turn of input.*/

            judge();

            
    if(chkWin() == WIN) break;

            
    if(stepFlg == 5 && chkPeace() == PEACE){

                printf(
    "Peace!");

                
    return 0;

            }

        }
    while(1);

        printf(
    "Hehe....I win this game~ :-p");

        
    return 0;

    }
     

    发表于 @ 2007年05月05日 14:53:00|评论(loading...)|编辑

    新一篇: C实现缓冲区溢出 | 旧一篇: C语言实现SMTP协议发送邮件

    评论

    #coco 发表于2008-10-11 16:17:37  IP: 125.125.168.*
    用cfree 运行下怎么有24个错误呀
    #coco 发表于2008-10-11 16:19:23  IP: 125.125.168.*
    能不能把正确的放上去

    急用

    你可以联系QQ:641530034

    谢谢
    #DL88250 发表于2008-10-11 16:49:17  IP: 221.213.43.*
    ....自己改下,应该是环境的问题。
    发表评论  


    登录
    Csdn Blog version 3.1a
    Copyright © 丁亮