Forráskód Böngészése

move out compat fn

Johann Woelper 6 éve
szülő
commit
9bec78ef16
4 módosított fájl, 226 hozzáadás és 44 törlés
  1. 19 19
      Cargo.lock
  2. BIN
      landscape.blend
  3. 88 8
      out.json
  4. 119 17
      src/main.rs

+ 19 - 19
Cargo.lock

@@ -151,9 +151,9 @@ name = "failure_derive"
 version = "0.1.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
  "synstructure 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -224,7 +224,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "proc-macro2"
-version = "1.0.5"
+version = "1.0.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -235,7 +235,7 @@ name = "quote"
 version = "1.0.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -347,17 +347,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "serde"
-version = "1.0.101"
+version = "1.0.102"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "serde_derive"
-version = "1.0.101"
+version = "1.0.102"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -367,7 +367,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -382,10 +382,10 @@ dependencies = [
 
 [[package]]
 name = "syn"
-version = "1.0.5"
+version = "1.0.7"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
@@ -395,9 +395,9 @@ name = "synstructure"
 version = "0.12.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
  "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -436,8 +436,8 @@ version = "0.1.0"
 dependencies = [
  "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)",
- "serde_derive 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
  "simplelog 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
@@ -492,7 +492,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09"
 "checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32"
 "checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b"
-"checksum proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "90cf5f418035b98e655e9cdb225047638296b862b42411c4e45bb88d700f7fc0"
+"checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27"
 "checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
 "checksum rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3ae1b169243eaf61759b8475a998f0a385e42042370f3a7dbaf35246eacc8412"
 "checksum rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853"
@@ -507,11 +507,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum rust-argon2 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ca4eaef519b494d1f2848fc602d18816fed808a981aedf4f1f00ceb7c9d32cf"
 "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
 "checksum ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8"
-"checksum serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)" = "9796c9b7ba2ffe7a9ce53c2287dfc48080f4b2b362fcc245a259b3a7201119dd"
-"checksum serde_derive 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)" = "4b133a43a1ecd55d4086bd5b4dc6c1751c68b1bfbeba7a5040442022c7e7c02e"
+"checksum serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4b39bd9b0b087684013a792c59e3e07a46a01d2322518d8a1104641a0b1be0"
+"checksum serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)" = "ca13fc1a832f793322228923fbb3aba9f3f44444898f835d31ad1b74fa0a2bf8"
 "checksum serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)" = "2f72eb2a68a7dc3f9a691bfda9305a1c017a6215e5a4545c258500d2099a37c2"
 "checksum simplelog 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "05a3e303ace6adb0a60a9e9e2fbc6a33e1749d1e43587e2125f7efa9c5e107c5"
-"checksum syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf"
+"checksum syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0e7bedb3320d0f3035594b0b723c8a28d7d336a3eda3881db79e61d676fb644c"
 "checksum synstructure 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f085a5855930c0441ca1288cf044ea4aecf4f43a91668abdb870b4ba546a203"
 "checksum term 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c0863a3345e70f61d613eab32ee046ccd1bcc5f9105fe402c61fcd0c13eeb8b5"
 "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"

BIN
landscape.blend


+ 88 - 8
out.json

@@ -119,14 +119,6 @@
             0.0
         ]
     },
-    {
-        "name": "grass",
-        "pos": [
-            -56.0,
-            -56.0,
-            0.0
-        ]
-    },
     {
         "name": "grass",
         "pos": [
@@ -278,5 +270,93 @@
             -40.0,
             0.0
         ]
+    },
+    {
+        "name": "grass",
+        "pos": [
+            -96.0,
+            -80.0,
+            0.0
+        ]
+    },
+    {
+        "name": "grass",
+        "pos": [
+            -56.0,
+            -80.0,
+            0.0
+        ]
+    },
+    {
+        "name": "road-corner-low-rot",
+        "pos": [
+            -72.0,
+            -40.0,
+            0.0
+        ]
+    },
+    {
+        "name": "road-straight-low",
+        "pos": [
+            -80.0,
+            -40.0,
+            0.0
+        ]
+    },
+    {
+        "name": "road-crossing-low",
+        "pos": [
+            -88.0,
+            -40.0,
+            0.0
+        ]
+    },
+    {
+        "name": "road-straight-low",
+        "pos": [
+            -96.0,
+            -40.0,
+            0.0
+        ]
+    },
+    {
+        "name": "road-end-low",
+        "pos": [
+            -104.0,
+            -40.0,
+            0.0
+        ]
+    },
+    {
+        "name": "road-straight-low-rot",
+        "pos": [
+            -88.0,
+            -32.0,
+            0.0
+        ]
+    },
+    {
+        "name": "building-office-small",
+        "pos": [
+            -80.0,
+            -32.0,
+            0.0
+        ]
+    },
+    {
+        "name": "building-office-small",
+        "pos": [
+            -56.0,
+            -56.0,
+            0.0
+        ]
+    },
+    {
+        "name": "building-office-small",
+        "pos": [
+            -96.0,
+            -32.0,
+            0.0
+        ]
     }
 ]

+ 119 - 17
src/main.rs

@@ -7,7 +7,7 @@ use std::io::BufReader;
 use std::io::BufWriter;
 // use std::ops::{Add, Sub, Div};
 use std::collections::HashMap;
-use std::ops::{Add, Mul};
+use std::ops::{Add, Mul, Neg};
 #[macro_use]
 extern crate log;
 extern crate simplelog;
@@ -53,7 +53,7 @@ impl V3 {
 
 impl fmt::Debug for V3 {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        write!(f, "V[{},{},{}]", self.x, self.y, self.z)
+        write!(f, "V[{},{},{}]", self.x*8, self.y*8, self.z*8)
     }
 }
 
@@ -90,6 +90,17 @@ impl Mul<i32> for V3 {
     }
 }
 
+impl Neg<> for V3 {
+    type Output = V3;
+    fn neg(self) -> V3 {
+        V3 {
+            x: -self.x,
+            y: -self.y,
+            z: -self.z,
+        }
+    }
+}
+
 impl<'a, 'b> Add<&'b V3> for &'a V3 {
     type Output = V3;
 
@@ -114,6 +125,19 @@ impl<'a> Mul<i32> for &'a V3 {
     }
 }
 
+
+impl<'a> Neg<> for &'a V3 {
+    type Output = V3;
+
+    fn neg(self) -> V3 {
+        V3 {
+            x: -self.x,
+            y: -self.y,
+            z: -self.z,
+        }
+    }
+}
+
 // impl Sub<V3> for  V3 {
 //     type Output = V3;
 //     fn sub(self, other: V3) -> V3 {
@@ -243,37 +267,115 @@ fn get_unsolved_neighbors(cell: &V3, grid: &HashMap<V3, String>) -> Vec<V3> {
     neighbors
 }
 
+fn template_meets_constraints(constraint: &HashMap<V3, String>, template: &HashMap<V3, Vec<String>>) -> bool {
+    
+    
+    for (c_pos, c_name) in constraint {
+        // let _x = template.get(&c_pos).map(|x| x.contains(c_name));
+        if let Some(possible_tiles) = template.get(&c_pos) {
+            
+        }
+    }
+    true
+}
+
 fn wfc_solver(
     training_data: &HashMap<String, HashMap<V3, Vec<String>>>,
     base_map: HashMap<V3, String>,
 ) -> HashMap<V3, String> {
     let mut new_grid = base_map;
+    // let gridsize = 8;
 
     for (pos, _name) in new_grid.clone() {
         for unsolved_neighbor in get_unsolved_neighbors(&pos, &new_grid) {
             println!("Unsolved {:?}", unsolved_neighbor);
+            let mut contraint_map: HashMap<V3, String> = HashMap::new();
+            
             for tile_neighbor in &unsolved_neighbor.offsets() {
                 let abs_neighbor_pos = &unsolved_neighbor + tile_neighbor;
 
                 if let Some(tn) = new_grid.get(&abs_neighbor_pos) {
                     println!("\tNeighbor {:?} exists, is {}", abs_neighbor_pos, tn);
                     // println!("\tTraining data for {} = {:?}", tn, training_data.get(tn).unwrap());
-                    let mut contraint_map: HashMap<V3, String> = HashMap::new();
-
-                    if let Some(constraints) = training_data.get(tn).unwrap().get(tile_neighbor) {
-                        // println!("\t{} points to me, accepts {:?}", tn, constraints);
-                        println!(
-                            "\t\tSolving {:?} - looking into neighbors",
-                            unsolved_neighbor
-                        );
-                        let cs = constraints.choose(&mut rand::thread_rng()).unwrap();
-                        println!("\t\tchose {:?}", cs);
-                        new_grid.insert(unsolved_neighbor, cs.to_string());
-                    } else {
-                        println!("\t\tNo training data in tile {} at offset {:?}", tn, tile_neighbor);
-                    }
+                    
+                    contraint_map.insert(tile_neighbor.clone(), tn.to_string());
+                    // if let Some(constraints) = training_data.get(tn).unwrap().get(&-tile_neighbor) {
+                    //     // println!("\t{} points to me, accepts {:?}", tn, constraints);
+                    //     println!(
+                    //         "\t\tlooking up in {} {:?}",
+                    //         tn, tile_neighbor
+                    //     );
+                    //     let cs = constraints.choose(&mut rand::thread_rng()).unwrap();
+                    //     println!("\t\tAdded a randomly chosen constraint: {:?}", cs);
+                    //     // new_grid.insert(unsolved_neighbor, cs.to_string());
+                    //     contraint_map.insert(tile_neighbor.clone(), cs.to_string());
+                        
+                    // } else {
+                    //     // println!("\t\tNo training data in tile {} at offset {:?}", tn, tile_neighbor);
+                    // }
+                    
                 }
             }
+            // Constraint map is ready here
+            // println!("All constraints: {:?}", contraint_map);
+            let num_constraints = contraint_map.len();
+            
+            println!("\tSolving {} contraints in {:?}", num_constraints, contraint_map );
+
+            
+            //let mut compatible = 0;
+            for (template_name, compatible_tiles) in training_data {
+                
+                //if compatible == num_constraints {break;}
+                println!("\t\tProbing template {:?}", template_name );
+                let _compat = template_meets_constraints(&contraint_map, compatible_tiles);
+                
+
+                //new_grid.insert(unsolved_neighbor, template_tile.to_string());
+
+                // // TODO: iterate through all combos at all the constraint positions
+                // for (p, constraint) in &contraint_map {
+                //     println!("\t\t\tWill {:?} {} fit?", p, constraint );
+                //     if let Some(tiles_for_this_pos) = compatible_tiles.get(&p) {
+                //         println!("\t\t\tAt the above pos, this is what the template offers: {:?}", tiles_for_this_pos );
+                //         if tiles_for_this_pos.contains(&constraint) {
+                //             compatible += 1;
+                //             if compatible == num_constraints {
+                //                 println!("\tSolved with {}.", template_tile);
+                //                 new_grid.insert(unsolved_neighbor, template_tile.to_string());
+                //                 break;
+                //             }
+                //         }
+                //     }
+                // }
+                
+
+                // println!("{}", compatible);
+            }
+
+            
+            // for (pos, tilename) in contraint_map {
+            //     println!("\tSolving {} constraint", tilename );
+            //     // Now find a suitable tile in training data
+            //     let mut compatible = 0;
+            //     for (template_tile, compatible_tiles) in training_data {
+            //         if let Some(tiles_for_this_pos) = compatible_tiles.get(&pos) {
+            //             if tiles_for_this_pos.contains(&tilename) {
+            //                 println!("\t{} template supports {} @{:?}", template_tile, tilename, pos, );
+            //                 compatible += 1;
+            //                 if compatible == num_constraints {
+            //                     println!("\t{} fits all criteria. Locking in at {:?}", template_tile, unsolved_neighbor*8);
+            //                     new_grid.insert(unsolved_neighbor, template_tile.to_string());
+
+            //                     break;
+
+            //                 }
+            //             }
+
+            //         }
+            //     }
+
+            // }
 
             // println!("Training data: {:?}", trained_data_for_this_tile);
         }
@@ -310,7 +412,7 @@ fn main() {
     // let new_grid: HashMap<V3, String> = HashMap::new();
     let mut base_map: HashMap<V3, String> = HashMap::new();
     // init start conditions
-    base_map.insert(V3::new(10, 0, 0), String::from("grass"));
+    base_map.insert(V3::new(0, 0, 0), String::from("grass"));
 
     for i in 1..3 {
         info!(