無 AI 版本,在框框內按滑鼠左鍵落子。
#include <windows.h> #include <stdio.h> extern "C" WINBASEAPI HWND WINAPI GetConsoleWindow(); int main (/* 090701 */) { short pos, x, y, ch = 0, rnd = 0, c[11] = {0}; short win[] = {7,56,73,84,146,273,292,448,0}, *w; char map[] = "□ □ □\n□ □ □\n□ □ □"; COORD coor = {0,0}; POINT p; puts (map); while (rnd < 9) { GetCursorPos (&p); ScreenToClient (GetConsoleWindow(), &p); pos = (x=p.x-2)/21 + ((y=p.y-2)/15)*3; if (x<0 || x>60 || y<0 || y>42 || c[pos] || GetAsyncKeyState (1)>=0) continue; SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), coor); map[pos*3] = "○╳"[ch*2 ]; map[pos*3+1] = "○╳"[ch*2+1]; puts (map); c[ch+9] |= (c[pos] = 1) << pos; for (w=win; *w; *w==(c[ch+9]&*w)? rnd=99, w=win+8: w++); if (rnd != 99) ch = !ch, rnd++; } system ("pause"+ !printf (9==rnd? "\n平手":"\n%c 獲勝", "OX"[ch])); }
沒有留言:
張貼留言