Init commit
This commit is contained in:
commit
655b7eacd1
|
@ -0,0 +1 @@
|
|||
/target
|
|
@ -0,0 +1,89 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "0.4.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
|
||||
|
||||
[[package]]
|
||||
name = "khetamine"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "edc3358ebc67bc8b7fa0c007f945b0b18226f78437d61bec735a9eb96b61ee70"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.130"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.130"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.68"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.80"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "khetamine"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0.130", features = ["derive"] }
|
||||
serde_json = "1.0.68"
|
|
@ -0,0 +1,24 @@
|
|||
// bored
|
||||
use crate::models::piece::Piece;
|
||||
|
||||
|
||||
fn print_board(board: Board) {
|
||||
println!("{}", board.iter().map(|row| row.iter().map(|p| p.to_string())..join(" ")).join("\n"));
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// let board = vec![
|
||||
// vec![Piece::Pharaoh],
|
||||
// vec![],
|
||||
// vec![],
|
||||
// vec![],
|
||||
// ];
|
||||
|
||||
// print_board(board);
|
||||
}
|
||||
|
||||
|
||||
fn is_legal_move() -> bool {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
use std::env;
|
||||
mod models {
|
||||
pub mod board;
|
||||
pub mod piece;
|
||||
pub mod networking;
|
||||
}
|
||||
|
||||
fn print_help() {
|
||||
println!("Ey fam, hmu with dat '--serve' or '--join <address>'")
|
||||
}
|
||||
|
||||
fn start_game() {
|
||||
println!("OK");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
if (args.len() == 2) && ((args[1] == "--serve") | (args[1] == "serve")) {
|
||||
|
||||
//Start game server
|
||||
println!("Serving!");
|
||||
start_game();
|
||||
|
||||
} else if (args.len() == 3) && ((args[1] == "--join") | (args[1] == "join")) {
|
||||
|
||||
//Join game server
|
||||
println!("Joining!");
|
||||
start_game();
|
||||
|
||||
} else if (args.len() == 2) && (args[1] == "--help") {
|
||||
|
||||
print_help();
|
||||
|
||||
} else {
|
||||
|
||||
println!("What do you mean with {:?}\n", args);
|
||||
print_help();
|
||||
|
||||
}
|
||||
|
||||
println!("{}", serialize_move(models::networking::Action::Rotate {
|
||||
from: (2, 2),
|
||||
rot: models::networking::RotationDirection::Positive
|
||||
}));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
fn serialize_move(action: models::networking::Action) -> str {
|
||||
let serialized = serde_json::to_string(&action);
|
||||
match serialized {
|
||||
Ok(s) => {
|
||||
println!("OK: {}", s);
|
||||
return &s;
|
||||
},
|
||||
Err(_e) => {
|
||||
println!("Couldn't serialize...");
|
||||
return ("");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
|
||||
// use crate::models::piece::Piece;
|
||||
|
||||
// #[derive(Display)]
|
||||
pub type Board = Vec<Vec<crate::models::piece::Piece>>;
|
|
@ -0,0 +1,17 @@
|
|||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum RotationDirection {
|
||||
Positive,
|
||||
Negative
|
||||
}
|
||||
|
||||
pub type Position = (u8, u8);
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(tag = "type")]
|
||||
pub enum Action {
|
||||
Move {from: Position, to: Position},
|
||||
Rotate {from: Position, rot: RotationDirection},
|
||||
Swap {from: Position, to: Position}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
use std::fmt;
|
||||
|
||||
enum DjedDirection {
|
||||
NorthWest,
|
||||
NorthEast,
|
||||
}
|
||||
|
||||
enum PyramidDirection {
|
||||
NorthWest,
|
||||
NorthEast,
|
||||
SouthEast,
|
||||
SouthWest,
|
||||
}
|
||||
|
||||
enum Stack {
|
||||
Single,
|
||||
Double,
|
||||
}
|
||||
|
||||
// #[derive(Display)]
|
||||
pub enum Piece {
|
||||
Pharaoh,
|
||||
Djed(DjedDirection),
|
||||
Pyramid(PyramidDirection),
|
||||
Obelisk(Stack)
|
||||
}
|
||||
|
||||
impl fmt::Display for Piece {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Piece::Pharaoh => write!(f, "Pharaoh"),
|
||||
Piece::Djed(_) => write!(f, "Djed"),
|
||||
Piece::Pyramid(_) => write!(f, "Pyramid"),
|
||||
Piece::Obelisk(_) => write!(f, "Obelisk"),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
//Go brooklyn!
|
||||
|
||||
use std::io::Write;
|
||||
use std::net::TcpStream;
|
||||
|
||||
fn client_connect(addr: String) -> () {
|
||||
const PORT: &str ="4446";
|
||||
let stream = TcpStream::connect(addr.to_owned() + ":" + PORT);
|
||||
match stream {
|
||||
Ok(mut s) => {
|
||||
let _res = s.write(b"Testing tcp! wack...\n"); ()
|
||||
},
|
||||
Err(e) => println!("[ERR]: Did not connect to port:\n{}", e),
|
||||
}
|
||||
}
|
||||
|
||||
// fn main() {
|
||||
// client_connect(String::from("127.0.0.1"));
|
||||
// }
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
use std::net::{TcpListener, TcpStream};
|
||||
use std::io;
|
||||
use std::io::Write;
|
||||
use std::io::Read;
|
||||
|
||||
fn handle_client(mut stream: TcpStream) {
|
||||
let _res = stream.write(b"Hello from the other side.\n");
|
||||
let mut line;
|
||||
loop {
|
||||
line = [0; 512];
|
||||
let result = stream.read(&mut line);
|
||||
match result {
|
||||
Ok(s) => {
|
||||
if s > 1 {
|
||||
println!("{}",s);
|
||||
} else {
|
||||
println!("Empty msg!");
|
||||
break;
|
||||
}
|
||||
();
|
||||
},
|
||||
Err(_e) => {
|
||||
println!("Oh no");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
()
|
||||
}
|
||||
|
||||
fn start_listener(address: &str) {
|
||||
println!("Listening on {}", address);
|
||||
let listener = TcpListener::bind(address).unwrap();
|
||||
for stream in listener.incoming() {
|
||||
match stream {
|
||||
Ok(s) => {
|
||||
handle_client(s);
|
||||
println!("Lost connection, retrying.\n");
|
||||
},
|
||||
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
|
||||
println!("What's going on here - Axel F");
|
||||
break;
|
||||
},
|
||||
Err(e) => panic!("encountered IO error: {}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
const PORT: &str ="4446";
|
||||
let full_address: String = "0.0.0.0:".to_owned() + PORT;
|
||||
|
||||
start_listener(&full_address);
|
||||
}
|
Loading…
Reference in New Issue