From 9b96e6486463b16bb7cd0bc69d33a59c46ffc25f Mon Sep 17 00:00:00 2001 From: pjvrmisk8 Date: Thu, 11 Jan 2024 21:18:14 +0800 Subject: [PATCH] ADD file via upload --- 简单井字棋.cpp | 172 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 简单井字棋.cpp diff --git a/简单井字棋.cpp b/简单井字棋.cpp new file mode 100644 index 0000000..1ef3a5b --- /dev/null +++ b/简单井字棋.cpp @@ -0,0 +1,172 @@ +#include +#include + + char arr[9] = { ' ',' ',' ',' ',' ',' ',' ',' ',' ' }; + + void print() + { + + std::cout << "Ϸ" << std::endl; + std::cout << "+---+---+---+" << std::endl; + std::cout << "| " << arr[0] << " | " << arr[1] << " | " << arr[2] << " |" << std::endl; + std::cout << "+---+---+---+" << std::endl; + std::cout << "| " << arr[3] << " | " << arr[4] << " | " << arr[5] << " |" << std::endl; + std::cout << "+---+---+---+" << std::endl; + std::cout << "| " << arr[6] << " | " << arr[7] << " | " << arr[8] << " |" << std::endl; + std::cout << "+---+---+---+" << std::endl; + + } + + int main() + { + bool n1{ 0 }, n2{ 0 }; + system("cls"); + print(); + int i{ 1 }, k{}; + unsigned long long n;//λ + int a{ 0 }, b{ 0 };//ӮֶԱ + int round{}; + + std::cout << "еϷ"; + std::cin >> round; + + + for (k = 1; k <= round; ++k) + { + for (i = 1; i <= 9; i = i + 1) + { + if (i % 2 == 1) + { + std::cout << "һѡλã"; + std::cin >> n; + if (arr[n - 1] != ' '||n>9||n<1) + { + std::cout << "λô" << std::endl; + std::cout << "ѡλ" << std::endl; + i = i - 1; + continue; + } + else + { + arr[n - 1] = 'X'; + } + } + else + { + std::cout << "Ҷѡλã"; + std::cin >> n; + if (arr[n - 1] != ' '||n>9||n<1) + { + std::cout << "λô" << std::endl; + std::cout << "ѡλ" << std::endl; + i = i - 1; + continue; + } + else + { + arr[n - 1] = 'O'; + } + } + system("cls"); + print(); + // + if (arr[0] == arr[1] && arr[1] == arr[2] && arr[2] != ' ') + { + if (arr[0] == 'O') + n2 = 1; + else + n1 = 1; + break; + } + + else if (arr[3] == arr[4] && arr[4] == arr[5] && arr[5] != ' ') + { + if (arr[3] == 'O') + n2 = 1; + else + n1 = 1; + break; + } + + else if (arr[6] == arr[7] && arr[7] == arr[8] && arr[8] != ' ') + { + if (arr[6] == 'O') + n2 = 1; + else + n1 = 1; + break; + } + + + else if (arr[0] == arr[3] && arr[3] == arr[6] && arr[6] != ' ') + { + if (arr[0] == 'O') + n2 = 1; + else + n1 = 1; + break; + } + + else if (arr[1] == arr[4] && arr[4] == arr[7] && arr[7] != ' ') + { + if (arr[1] == 'O') + n2 = 1; + else + n1 = 1; + break; + } + + else if (arr[2] == arr[5] && arr[5] == arr[8] && arr[8] != ' ') + { + if (arr[2] == 'O') + n2 = 1; + else + n1 = 1; + break; + } + + //б + else if (arr[0] == arr[4] && arr[4] == arr[8] && arr[8] != ' ') + { + if (arr[0] == 'O') + n2 = 1; + else + n1 = 1; + break; + } + + else if (arr[6] == arr[4] && arr[4] == arr[2] && arr[2] != ' ') + { + if (arr[6] == 'O') + n2 = 1; + else + n1 = 1; + break; + } + + } + //ж + if (n1 == 1) + ++a; + else if (n2 == 1) + ++b; + std::cout << "ȷֶԱ 12=" << a << ':' << b << std::endl; + n1 = 0, n2 = 0; + for (i = 0; i < 9; ++i) + arr[i] = ' '; + } + + //ж + + if (a>b) + std::cout << "1 win!!!"; + else if (a