Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp
00001 #include "mbed.h" 00002 00003 int map[5][5][5]; 00004 int i , j , k , player , button , x ,y , z; 00005 int check1[5][5][5] , check2[5][5][5]; 00006 00007 void Check_case1(){ //คนแรกชนะ 00008 printf("Player 1 WIN!"); 00009 } 00010 00011 void Check_case2(){ //คน2ชนะ 00012 printf("Player 2 WIN!"); 00013 } 00014 00015 void Check_error(){ //เช็คคนแพ้ 00016 if(player == 1){ 00017 printf("Player 1 LOSE!"); 00018 } 00019 else{ 00020 printf("Player 2 LOSE!"); 00021 } 00022 } 00023 00024 void Check_map(){ //แสดงmap 00025 for(x=0 ; x<5 ; x++){ 00026 for(y=0 ; y<5 ; y++){ 00027 for(z=0 ; z<5 ; z++){ 00028 if(map[x][y][z] == 5){ 00029 check1[x][y][z] = 1; 00030 } 00031 else if(map[x][y][z] == 6){ 00032 check2[x][y][z] = 1; 00033 } 00034 else{ 00035 check1[x][y][z] = 0; 00036 check2[x][y][z] = 0; 00037 } 00038 } 00039 } 00040 } 00041 } 00042 00043 int main(){ 00044 while(1){ 00045 00046 switch(player){ // เลือกตำแหน่งคนลง 00047 00048 case '1': 00049 i-- , j-- , k--; 00050 if(map[i][j][k] == 0){ 00051 map[i][j][k] = 5; // 5 = 'x' 00052 } 00053 else{ 00054 Check_error(); // ลงไมไ่ด้ 00055 } 00056 case '2': 00057 i-- , j-- , k--; 00058 if(map[i][j][k] == 0){ 00059 map[i][j][k] = 6; // 6 = 'o' 00060 } 00061 else{ 00062 Check_error(); // ลงไมไ่ด้ 00063 } 00064 } 00065 00066 if(i == 5 or j == 5 or k == 5){ // ลงเกิน map 00067 check_error(); 00068 } 00069 00070 for(i=0 ; i<5 ; i++){ //แนว k 00071 for(j=0 ; j<5 ; j++){ 00072 for(k=0 ; k<3 ; k++){ 00073 if(map[i][j][k] and map[i][j][k+1] and map[i][j][k+2] == 5){ 00074 Check_case1(); 00075 } 00076 else if(map[i][j][k] and map[i][j][k+1] and map[i][j][k+2] == 6){ 00077 Check_case2(); 00078 } 00079 } 00080 } 00081 } 00082 00083 for(i=0 ; i<5 ; i++){ // แนว j 00084 for(k=0 ; k<5 ; k++){ 00085 for(j=0 ; j<3 ; j++){ 00086 if(map[i][j][k] and map[i][j+1][k] and map[i][j+2][k] == 5){ 00087 Check_case1(); 00088 } 00089 else if(map[i][j][k] and map[i][j+1][k] and map[i][j+2][k] == 6){ 00090 Check_case2(); 00091 } 00092 } 00093 } 00094 } 00095 00096 for(j=0 ; j<5 ; j++){ // แนว i 00097 for(k=0 ; k<5 ; k++){ 00098 for(i=0 ; i<3 ; i++){ 00099 if(map[i][j][k] and map[i+1][j][k] and map[i+2][j][k] == 5){ 00100 Check_case1(); 00101 } 00102 else if(map[i][j][k] and map[i+1][j][k] and map[i+2][j][k] == 6){ 00103 Check_case2(); 00104 } 00105 } 00106 } 00107 } 00108 00109 for(i=0 ; i<5 ; i++){ // แนวทแยง i เป็นฐานขึ้น 00110 for(j=0 ; j<3 ; j++){ 00111 for(k=0 ; k<3 ; k++){ 00112 if(map[i][j][k] and map[i][j+1][k+1] and map[i][j+2][k+2] == 5){ 00113 Check_case1(); 00114 } 00115 else if(map[i][j][k] and map[i][j+1][k+1] and map[i][j+2][k+2] == 6){ 00116 Check_case2(); 00117 } 00118 } 00119 } 00120 } 00121 00122 for(j=0 ; j<5 ; j++){ // แนวทแยง j เป็นฐานขึ้น 00123 for(i=0 ; i<3 ; i++){ 00124 for(k=0 ; k<3 ; k++){ 00125 if(map[i][j][k] and map[i+1][j][k+1] and map[i+2][j][k+2] == 5){ 00126 Check_case1(); 00127 } 00128 else if(map[i][j][k] and map[i+1][j][k+1] and map[i+2][j][k+2] == 6){ 00129 Check_case2(); 00130 } 00131 } 00132 } 00133 } 00134 00135 for(k=0 ; k<5 ; k++){ // แนวทแยง k เป็นฐานขึ้น 00136 for(i=0 ; i<3 ; i++){ 00137 for(j=0 ; j<3 ; j++){ 00138 if(map[i][j][k] and map[i+1][j+1][k] and map[i+2][j+2][k] == 5){ 00139 Check_case1(); 00140 } 00141 else if(map[i][j][k] and map[i+1][j+1][k] and map[i+2][j+2][k] == 6){ 00142 Check_case2(); 00143 } 00144 } 00145 } 00146 } 00147 00148 for(i=0 ; i<5 ; i++){ // แนวทแยง i เป็นฐานลง 00149 for(j=0 ; j<3 ; j++){ 00150 for(k=4 ; k>1 ; k--){ 00151 if(map[i][j][k] and map[i][j+1][k-1] and map[i][j+2][k-2] == 5){ 00152 Check_case1(); 00153 } 00154 else if(map[i][j][k] and map[i][j+1][k-1] and map[i][j+2][k-2] == 6){ 00155 Check_case2(); 00156 } 00157 } 00158 } 00159 } 00160 00161 for(j=0 ; j<5 ; j++){ // แนวทแยง j เป็นฐานลง 00162 for(i=0 ; i<3 ; i++){ 00163 for(k=4 ; k>1 ; k--){ 00164 if(map[i][j][k] and map[i+1][j][k-1] and map[i+2][j][k-2] == 5){ 00165 Check_case1(); 00166 } 00167 else if(map[i][j][k] and map[i+1][j][k-1] and map[i+2][j][k-2] == 6){ 00168 Check_case2(); 00169 } 00170 } 00171 } 00172 } 00173 00174 for(k=0 ; k<5 ; k++){ // แนวทแยง k เป็นฐานลง 00175 for(i=0 ; i<3 ; i++){ 00176 for(j=4 ; j>1 ; j--){ 00177 if(map[i][j][k] and map[i+1][j-1][k] and map[i+2][j-2][k] == 5){ 00178 Check_case1(); 00179 } 00180 else if(map[i][j][k] and map[i+1][j-1][k] and map[i+2][j-2][k] == 6){ 00181 Check_case2(); 00182 } 00183 } 00184 } 00185 } 00186 for(i=0 ; i<3 ; i++){ // แนวทแยงแบบตัด1 00187 for(j=0 ; j<3 ; j++){ 00188 for(k=0 ; k<3 ; k++){ 00189 if(map[i][j][k] and map[i+1][j+1][k+1] and map[i+2][j+2][k+2] == 5){ 00190 Check_case1(); 00191 } 00192 else if(map[i][j][k] and map[i+1][j+1][k+1] and map[i+2][j+2][k+2] == 6){ 00193 Check_case2(); 00194 } 00195 } 00196 } 00197 } 00198 for(i=4 ; i>1 ; i--){ // แนวทแยงแบบตัด2 00199 for(j=0 ; j<3 ; j++){ 00200 for(k=0 ; k<3 ; k++){ 00201 if(map[i][j][k] and map[i-1][j+1][k+1] and map[i-2][j+2][k+2] == 5){ 00202 Check_case1(); 00203 } 00204 else if(map[i][j][k] and map[i-1][j+1][k+1] and map[i-2][j+2][k+2] == 6){ 00205 Check_case2(); 00206 } 00207 } 00208 } 00209 } 00210 for(i=4 ; i>1 ; i--){ // แนวทแยงแบบตัด 3 00211 for(j=4 ; j>1 ; j--){ 00212 for(k=0 ; k<3 ; k++){ 00213 if(map[i][j][k] and map[i-1][j-1][k+1] and map[i-2][j-2][k+2] == 5){ 00214 Check_case1(); 00215 } 00216 else if(map[i][j][k] and map[i-1][j-1][k+1] and map[i-2][j-2][k+2] == 6){ 00217 Check_case2(); 00218 } 00219 } 00220 } 00221 } 00222 for(i=0 ; i<3 ; i++){ // แนวทแยงแบบตัด4 00223 for(j=4 ; j>1 ; j--){ 00224 for(k=0 ; k<3 ; k++){ 00225 if(map[i][j][k] and map[i+1][j-1][k+1] and map[i+2][j-2][k+2] == 5){ 00226 Check_case1(); 00227 } 00228 else if(map[i][j][k] and map[i+1][j-1][k+1] and map[i+2][j-2][k+2] == 6){ 00229 Check_case2(); 00230 } 00231 } 00232 } 00233 } 00234 00235 00236 } 00237 00238 }
Generated on Tue Jul 19 2022 14:25:52 by
1.7.2