check map

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
silvermist
Date:
Sat Dec 03 18:43:42 2016 +0000
Commit message:
???????

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 151948e45f6a main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Dec 03 18:43:42 2016 +0000
@@ -0,0 +1,238 @@
+#include "mbed.h"
+
+int map[5][5][5];
+int i , j , k , player , button , x ,y , z; 
+int check1[5][5][5] , check2[5][5][5];
+
+void Check_case1(){                 //คนแรกชนะ
+    printf("Player 1 WIN!");
+}
+
+void Check_case2(){                 //คน2ชนะ
+    printf("Player 2 WIN!");
+    }
+
+void Check_error(){                 //เช็คคนแพ้
+    if(player == 1){
+        printf("Player 1 LOSE!");
+        }
+    else{
+        printf("Player 2 LOSE!");
+        }
+    }
+
+void Check_map(){                   //แสดงmap
+    for(x=0 ; x<5 ; x++){
+        for(y=0 ; y<5 ; y++){ 
+            for(z=0 ; z<5 ; z++){
+                if(map[x][y][z] == 5){
+                    check1[x][y][z] = 1;
+                    }
+                else if(map[x][y][z] == 6){
+                    check2[x][y][z] = 1;
+                    }
+                else{
+                    check1[x][y][z] = 0;
+                    check2[x][y][z] = 0;
+                    }
+                } 
+            }
+        }
+    }
+    
+int main(){
+    while(1){
+        
+        switch(player){                             // เลือกตำแหน่งคนลง
+            
+            case '1':
+            i-- , j-- , k--;
+                if(map[i][j][k] == 0){
+                    map[i][j][k] = 5;               // 5 = 'x'
+                    }
+                else{
+                    Check_error();                  // ลงไมไ่ด้
+                    }
+            case '2':
+                i-- , j-- , k--;
+                if(map[i][j][k] == 0){
+                    map[i][j][k] = 6;               // 6 = 'o'
+                    }
+                else{
+                    Check_error();                  // ลงไมไ่ด้
+                    }
+            }
+    
+        if(i == 5 or j == 5 or k == 5){             // ลงเกิน map
+            check_error();
+            }
+        
+        for(i=0 ; i<5 ; i++){          //แนว k
+            for(j=0 ; j<5 ; j++){
+                for(k=0 ; k<3 ; k++){
+                    if(map[i][j][k] and map[i][j][k+1] and map[i][j][k+2] == 5){
+                        Check_case1();
+                            }
+                    else if(map[i][j][k] and map[i][j][k+1] and map[i][j][k+2] == 6){
+                        Check_case2();
+                            }
+                        }
+                    }
+                }
+        
+        for(i=0 ; i<5 ; i++){           // แนว j
+            for(k=0 ; k<5 ; k++){
+                for(j=0 ; j<3 ; j++){   
+                    if(map[i][j][k] and map[i][j+1][k] and map[i][j+2][k] == 5){
+                        Check_case1();
+                            }
+                    else if(map[i][j][k] and map[i][j+1][k] and map[i][j+2][k] == 6){
+                        Check_case2();
+                            }
+                        }
+                    }
+                }  
+        
+        for(j=0 ; j<5 ; j++){           // แนว i
+            for(k=0 ; k<5 ; k++){
+                for(i=0 ; i<3 ; i++){
+                    if(map[i][j][k] and map[i+1][j][k] and map[i+2][j][k] == 5){
+                        Check_case1();
+                            }
+                    else if(map[i][j][k] and map[i+1][j][k] and map[i+2][j][k] == 6){
+                        Check_case2();
+                            }
+                        }
+                    }
+                } 
+                
+        for(i=0 ; i<5 ; i++){       // แนวทแยง i เป็นฐานขึ้น
+            for(j=0 ; j<3 ; j++){
+                for(k=0 ; k<3 ; k++){
+                    if(map[i][j][k] and map[i][j+1][k+1] and map[i][j+2][k+2] == 5){
+                         Check_case1();
+                        }
+                    else if(map[i][j][k] and map[i][j+1][k+1] and map[i][j+2][k+2] == 6){
+                         Check_case2();
+                        }
+                    }
+                }
+            }
+            
+        for(j=0 ; j<5 ; j++){       // แนวทแยง j เป็นฐานขึ้น
+            for(i=0 ; i<3 ; i++){
+                for(k=0 ; k<3 ; k++){
+                    if(map[i][j][k] and map[i+1][j][k+1] and map[i+2][j][k+2] == 5){
+                         Check_case1();
+                        }
+                    else if(map[i][j][k] and map[i+1][j][k+1] and map[i+2][j][k+2] == 6){
+                         Check_case2();
+                        }
+                    }
+                }
+            }
+            
+        for(k=0 ; k<5 ; k++){       // แนวทแยง k เป็นฐานขึ้น
+            for(i=0 ; i<3 ; i++){
+                for(j=0 ; j<3 ; j++){
+                    if(map[i][j][k] and map[i+1][j+1][k] and map[i+2][j+2][k] == 5){
+                        Check_case1();
+                        }
+                    else if(map[i][j][k] and map[i+1][j+1][k] and map[i+2][j+2][k] == 6){
+                         Check_case2();
+                        }
+                    }
+                }
+            }
+            
+        for(i=0 ; i<5 ; i++){       // แนวทแยง i เป็นฐานลง
+            for(j=0 ; j<3 ; j++){
+                for(k=4 ; k>1 ; k--){
+                    if(map[i][j][k] and map[i][j+1][k-1] and map[i][j+2][k-2] == 5){
+                         Check_case1();
+                        }
+                    else if(map[i][j][k] and map[i][j+1][k-1] and map[i][j+2][k-2] == 6){
+                         Check_case2();
+                        }
+                    }
+                }
+            }
+            
+        for(j=0 ; j<5 ; j++){       // แนวทแยง j เป็นฐานลง
+            for(i=0 ; i<3 ; i++){
+                for(k=4 ; k>1 ; k--){
+                    if(map[i][j][k] and map[i+1][j][k-1] and map[i+2][j][k-2] == 5){
+                         Check_case1();
+                        }
+                    else if(map[i][j][k] and map[i+1][j][k-1] and map[i+2][j][k-2] == 6){
+                         Check_case2();
+                        }
+                    }
+                }
+            }
+            
+         for(k=0 ; k<5 ; k++){      // แนวทแยง k เป็นฐานลง
+            for(i=0 ; i<3 ; i++){
+                for(j=4 ; j>1 ; j--){
+                    if(map[i][j][k] and map[i+1][j-1][k] and map[i+2][j-2][k] == 5){
+                         Check_case1();
+                        }
+                    else if(map[i][j][k] and map[i+1][j-1][k] and map[i+2][j-2][k] == 6){
+                         Check_case2();
+                        }
+                    }
+                }
+            }
+        for(i=0 ; i<3 ; i++){       // แนวทแยงแบบตัด1
+            for(j=0 ; j<3 ; j++){
+               for(k=0 ; k<3 ; k++){
+                   if(map[i][j][k] and map[i+1][j+1][k+1] and map[i+2][j+2][k+2] == 5){
+                        Check_case1();
+                       }   
+                    else if(map[i][j][k] and map[i+1][j+1][k+1] and map[i+2][j+2][k+2] == 6){
+                        Check_case2();
+                        }
+                    }
+                }
+            }
+        for(i=4 ; i>1 ; i--){       // แนวทแยงแบบตัด2
+            for(j=0 ; j<3 ; j++){
+               for(k=0 ; k<3 ; k++){
+                   if(map[i][j][k] and map[i-1][j+1][k+1] and map[i-2][j+2][k+2] == 5){
+                        Check_case1();
+                       }   
+                    else if(map[i][j][k] and map[i-1][j+1][k+1] and map[i-2][j+2][k+2] == 6){
+                        Check_case2();
+                        }
+                    }
+                }
+            }
+        for(i=4 ; i>1 ; i--){       // แนวทแยงแบบตัด 3
+            for(j=4 ; j>1 ; j--){
+               for(k=0 ; k<3 ; k++){
+                   if(map[i][j][k] and map[i-1][j-1][k+1] and map[i-2][j-2][k+2] == 5){
+                        Check_case1();
+                       }   
+                    else if(map[i][j][k] and map[i-1][j-1][k+1] and map[i-2][j-2][k+2] == 6){
+                        Check_case2();
+                        }
+                    }
+                }
+            }
+        for(i=0 ; i<3 ; i++){       // แนวทแยงแบบตัด4
+            for(j=4 ; j>1 ; j--){
+               for(k=0 ; k<3 ; k++){
+                   if(map[i][j][k] and map[i+1][j-1][k+1] and map[i+2][j-2][k+2] == 5){
+                        Check_case1();
+                       }   
+                    else if(map[i][j][k] and map[i+1][j-1][k+1] and map[i+2][j-2][k+2] == 6){
+                        Check_case2();
+                        }
+                    }
+                }
+            }
+               
+                
+            }
+            
+        }
\ No newline at end of file
diff -r 000000000000 -r 151948e45f6a mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Dec 03 18:43:42 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/0ab6a29f35bf
\ No newline at end of file