小编Dar*_*der的帖子

使用python与stockfish通信

我用 pygame 制作了一个国际象棋游戏 GUI,现在我想添加一个计算机玩家,在这种情况下将是鳕鱼。github 仓库: https: //github.com/Dark-Leader/Chess

抱歉,我无法在这里显示代码..它是多个文件。目前,游戏非常适合玩家对玩家。看一下 main.py 文件:

import pygame
from chess.constants import WIDTH, HEIGHT, FPS, BOARD_EDGE
from chess.game import Game
from chess.engine import Engine
pygame.init()
window = pygame.display.set_mode((WIDTH + BOARD_EDGE * 2, HEIGHT + BOARD_EDGE * 2))
pygame.display.set_caption("Chess")
clock = pygame.time.Clock()
game = Game(window)
# engine = Engine()
# engine.get_response()
# engine.put_command("uci")
# engine.get_response()
# engine.put_command('quit')

running = True
while running:
    clock.tick(FPS)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

        if event.type == pygame.MOUSEBUTTONDOWN: …
Run Code Online (Sandbox Code Playgroud)

python chess

5
推荐指数
0
解决办法
5069
查看次数

scanf() 失败后如何清除输入缓冲区?

scanf()我的程序中的输入缓冲区有问题。

首先我要求用户输入:

char someVariable;
printf("Enter text: ");
scanf(" %c",&someVariable);
Run Code Online (Sandbox Code Playgroud)

然后我有一个循环,一次遍历输入一个字符,scanf()直到到达换行符。

问题是,循环完成后,不知何故,缓冲区中仍然有一些东西,因此这个函数(在循环中被调用)被再次调用并破坏了我程序中的逻辑。

如何强制清除输入缓冲区?

我只能使用scanf()(作业要求)

void checkType(){
    char userInput;
    char tempCheckInput;
    printf("Enter Text: ");
    scanf(" %c",&userInput);
    while (userInput != '\n'){

        tempCheckInput = userInput;
        scanf("%c",&userInput);
Run Code Online (Sandbox Code Playgroud)

忽略循环结束;这是我获取输入的部分。

c scanf input-buffer

2
推荐指数
1
解决办法
171
查看次数

标签 统计

c ×1

chess ×1

input-buffer ×1

python ×1

scanf ×1