第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

c語言版本實(shí)現(xiàn)的五子棋

標(biāo)簽:
C C++
#include <stdio.h>
#include <stdlib.h>

#define N    5

int chessboard[N + 1][N + 1] = { 0 };

int whoseTurn = 0;

void initGame();
void printChessboard();
void playChess();
int judge(int, int);

int main()
{
    initGame();
    while (1)
    {
        ++whoseTurn;
        playChess();
    }
    return 0;
}

void initGame(void)
{
    char c;

    printf("Please input \'y\' to enter the game:");
    c = getchar();
    if ('y' != c && 'Y' != c)
        exit(0);

    system("cls");
    printChessboard();
}

void printChessboard()
{
    int i, j;

    for (i = 0; i <= N; i++)
    {
        for (j = 0; j <= N; j++)
        {
            if (0 == i)
                printf("%3d", j);
            else if (j == 0)
                printf("%3d", i);
            else if (1 == chessboard[i][j])
                printf("  O");
            else if (2 == chessboard[i][j])
                printf("  X");
            else
                printf("  *");
        }
        printf("\n");
    }
}

void playChess(void)
{
    int i, j;

    if (1 == (whoseTurn & 1))
    {
        printf("Turn to player 1, please input the position:");
        scanf_s("%d %d", &i, &j);

        while (chessboard[i][j] != 0)
        {
            printf("This position  has been occupied, please input the position again:");
            scanf_s("%d %d", &i, &j);
        }

        chessboard[i][j] = 1;
    }
    else
    {
        printf("Turn to player 1, please input the position:");
        scanf_s("%d %d", &i, &j);

        while (chessboard[i][j] != 0)
        {
            printf("This position  has been occupied, please input the position again:");
            scanf_s("%d %d", &i, &j);
        }

        chessboard[i][j] = 2;
    }

    system("cls");
    printChessboard();

    if (judge(i, j))
    {
        if (1 == (whoseTurn & 1))
        {
            printf("Winner is player 1!\n");
            exit(0);
        }
        else
        {
            printf("Winner is player 2!\n");
            exit(0);
        }
    }
}

int judge(int x, int y)
{
    int i, j;
    int t = 2 - (whoseTurn & 1);

    for (i = x - 4, j = y; i <= x; i++)
    {
        if (i >= 1 && i <= N - 4 && t == chessboard[i][j] && t == chessboard[i + 1][j] && t == chessboard[i + 2][j] && t == chessboard[i + 3][j] && t == chessboard[i + 4][j])
            return 1;
    }
    for (i = x, j = y - 4; j <= y; j++)
    {
        if (j >= 1 && j <= N - 4 && t == chessboard[i][j] && t == chessboard[i][j + 1] && t == chessboard[i][j + 2] && t == chessboard[i][j + 3] && t == chessboard[i][j + 4])
            return 1;
    }
    for (i = x - 4, j = y - 4; i <= x, j <= y; i++, j++)
    {
        if (i >= 1 && i <= N - 4 && j >= 1 && j <= N - 4 && t == chessboard[i][j] && t == chessboard[i + 1][j + 1] && t == chessboard[i + 2][j + 2] && t == chessboard[i + 3][j + 3] && t == chessboard[i + 4][j + 4])
            return 1;
    }
    for (i = x + 4, j = y - 4; i >= 1, j <= y; i--, j++)
    {
        if (i >= 1 && i <= N - 4 && j >= 1 && j <= N - 4 && t == chessboard[i][j] && t == chessboard[i - 1][j + 1] && t == chessboard[i - 2][j + 2] && t == chessboard[i - 3][j + 3] && t == chessboard[i - 4][j + 4])
            return 1;
    }

    return 0;
}
點(diǎn)擊查看更多內(nèi)容
50人點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
JAVA開發(fā)工程師
手記
粉絲
56
獲贊與收藏
363

關(guān)注作者,訂閱最新文章

閱讀免費(fèi)教程

感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消