Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build example games #22

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/game/mock/example.rs

This file was deleted.

139 changes: 139 additions & 0 deletions src/game/mock/example/general_utility/general_sum/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
//! # Example Game Module - General Utility General Sum [WIP]
//!
//! This module contains games of type tree, acyclic, and cyclic that
//! adhere to the following definitions:
//! General Utility - Player utilities are expressed numerically.
//! General Sum - Sum of all utilities is not necessarily zero.

/* IMPORTS */

use crate::game::mock::example::{
AcyclicExampleGame, CyclicExampleGame, TreeExampleGame, Visualizer,
};
use crate::game::mock::{builder, Node};
use crate::node;
use anyhow::Result;

/* CONSTANTS */

const TREE_GAME_NAME: &str = "general-utility-general-sum-tree-structure";
const ACYCLIC_GAME_NAME: &str = "general-utility-general-sum-acyclic-structure";
const CYCLIC_GAME_NAME: &str = "general-utility-general-sum-cyclic-structure";

/* DEFINITIONS */

trait ExampleGame<'a>: Sized {
fn new(nodes: &'a mut Vec<Node>) -> Result<Self>;
}

/* IMPLEMENTATIONS */

impl<'a> ExampleGame<'a> for TreeExampleGame<'a> {
fn new(store: &'a mut Vec<Node>) -> Result<TreeExampleGame<'a>> {
let mut nodes = vec![
node!(0),
node!(1),
node!(1),
node!(1),
node!(0),
node!(0),
node!(0),
node!(0),
node!(0),
node!(0),
node![-1, 1],
node![2, -3],
node![2, 1],
node![0, 0],
node![4, 5],
node![-1, -2],
node![-2, 2],
node![4, -5],
node![-1, 0],
];

let length = store.len();
store.append(&mut nodes);
let store = &store[length..];

let game = builder::SessionBuilder::new(&TREE_GAME_NAME)
.edge(&store[0], &store[1])?
.edge(&store[0], &store[2])?
.edge(&store[0], &store[3])?
.edge(&store[1], &store[4])?
.edge(&store[1], &store[5])?
.edge(&store[1], &store[6])?
.edge(&store[2], &store[7])?
.edge(&store[2], &store[8])?
.edge(&store[2], &store[9])?
.edge(&store[3], &store[10])?
.edge(&store[3], &store[11])?
.edge(&store[3], &store[12])?
.edge(&store[4], &store[13])?
.edge(&store[5], &store[14])?
.edge(&store[6], &store[15])?
.edge(&store[7], &store[16])?
.edge(&store[8], &store[17])?
.edge(&store[9], &store[18])?
.start(&store[0])?
.build()?;

Ok(TreeExampleGame { game })
}
}

impl<'a> ExampleGame<'a> for AcyclicExampleGame<'a> {
fn new(store: &'a mut Vec<Node>) -> Result<AcyclicExampleGame<'a>> {
todo!()
}
}

impl<'a> ExampleGame<'a> for CyclicExampleGame<'a> {
fn new(store: &'a mut Vec<Node>) -> Result<CyclicExampleGame<'a>> {
todo!()
}
}

/* TESTING */

#[cfg(test)]
mod tests {
use super::*;
use anyhow::Result;

#[test]
fn initialize_example_tree_game() -> Result<()> {
let _ = TreeExampleGame::new(&mut vec![])?;
Ok(())
}

#[test]
fn initialize_example_acyclic_game() -> Result<()> {
let _ = AcyclicExampleGame::new(&mut vec![])?;
Ok(())
}

#[test]
fn initialize_example_cyclic_game() -> Result<()> {
let _ = CyclicExampleGame::new(&mut vec![])?;
Ok(())
}

#[test]
fn visualize_example_tree_game() -> Result<()> {
let _ = TreeExampleGame::new(&mut vec![])?.visualize();
Ok(())
}

#[test]
fn visualize_example_acyclic_game() -> Result<()> {
let _ = AcyclicExampleGame::new(&mut vec![])?.visualize();
Ok(())
}

#[test]
fn visualize_example_cyclic_game() -> Result<()> {
let _ = CyclicExampleGame::new(&mut vec![])?.visualize();
Ok(())
}
}
10 changes: 10 additions & 0 deletions src/game/mock/example/general_utility/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//! # Example Game Module - General Utility [WIP]
//!
//! This module contains games of type tree, acyclic, and cyclic that
//! adhere to the following definitions:
//! General Utility - Player utilities are expressed numerically.

/* SUBMODULES */

pub mod general_sum;
pub mod zero_sum;
91 changes: 91 additions & 0 deletions src/game/mock/example/general_utility/zero_sum/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//! # Example Game Module - General Utility Zero Sum [WIP]
//!
//! This module contains games of type tree, acyclic, and cyclic that
//! adhere to the following definitions:
//! General Utility - Player utilities are expressed numerically.
//! Zero Sum - Sum of all utilities is zero.

/* IMPORTS */

use crate::game::mock::example::{
AcyclicExampleGame, CyclicExampleGame, TreeExampleGame, Visualizer,
};
use crate::game::mock::{builder, Node};
use crate::node;
use anyhow::Result;

/* CONSTANTS */

const TREE_GAME_NAME: &str = "general-utility-zero-sum-tree-structure";
const ACYCLIC_GAME_NAME: &str = "general-utility-zero-sum-acyclic-structure";
const CYCLIC_GAME_NAME: &str = "general-utility-zero-sum-cyclic-structure";

/* DEFINITIONS */

trait ExampleGame<'a>: Sized {
fn new(nodes: &'a mut Vec<Node>) -> Result<Self>;
}

/* IMPLEMENTATIONS */

impl<'a> ExampleGame<'a> for TreeExampleGame<'a> {
fn new(store: &'a mut Vec<Node>) -> Result<TreeExampleGame<'a>> {
todo!()
}
}

impl<'a> ExampleGame<'a> for AcyclicExampleGame<'a> {
fn new(store: &'a mut Vec<Node>) -> Result<AcyclicExampleGame<'a>> {
todo!()
}
}

impl<'a> ExampleGame<'a> for CyclicExampleGame<'a> {
fn new(store: &'a mut Vec<Node>) -> Result<CyclicExampleGame<'a>> {
todo!()
}
}

/* TESTING */

#[cfg(test)]
mod tests {
use super::*;
use anyhow::Result;

#[test]
fn initialize_example_tree_game() -> Result<()> {
let _ = TreeExampleGame::new(&mut vec![])?;
Ok(())
}

#[test]
fn initialize_example_acyclic_game() -> Result<()> {
let _ = AcyclicExampleGame::new(&mut vec![])?;
Ok(())
}

#[test]
fn initialize_example_cyclic_game() -> Result<()> {
let _ = CyclicExampleGame::new(&mut vec![])?;
Ok(())
}

#[test]
fn visualize_example_tree_game() -> Result<()> {
let _ = TreeExampleGame::new(&mut vec![])?.visualize();
Ok(())
}

#[test]
fn visualize_example_acyclic_game() -> Result<()> {
let _ = AcyclicExampleGame::new(&mut vec![])?.visualize();
Ok(())
}

#[test]
fn visualize_example_cyclic_game() -> Result<()> {
let _ = CyclicExampleGame::new(&mut vec![])?.visualize();
Ok(())
}
}
77 changes: 77 additions & 0 deletions src/game/mock/example/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//! # Example Mock Test Game Module [WIP]
//!
//! This module provides sub modules with concrete examples of small games that adhere
//! to useful interface definitions that can be used for testing purposes. The games here
//! are built over the `mock` game graph implementation.

/* IMPORTS */

use crate::game::mock::{MockGame, Session};
use anyhow::Result;

/* CONSTANTS */

const MODULE_STORAGE: &str = "mock-game-examples";

/* SUBMODULES */

pub mod general_utility;
pub mod simple_utility;

/* DEFINITIONS */

pub struct TreeExampleGame<'a> {
game: Session<'a>,
}

pub struct AcyclicExampleGame<'a> {
game: Session<'a>,
}

pub struct CyclicExampleGame<'a> {
game: Session<'a>,
}

pub trait Visualizer {
fn visualize(&self) -> Result<()>;
}

/* TRAVERSAL IMPLEMENTATIONS */

impl MockGame for TreeExampleGame<'_> {
fn game(&self) -> &Session<'_> {
&self.game
}
}

impl MockGame for AcyclicExampleGame<'_> {
fn game(&self) -> &Session<'_> {
&self.game
}
}

impl MockGame for CyclicExampleGame<'_> {
fn game(&self) -> &Session<'_> {
&self.game
}
}

/* VISUALIZER IMPLEMENTATIONS */

impl Visualizer for TreeExampleGame<'_> {
fn visualize(&self) -> Result<()> {
self.game.visualize(MODULE_STORAGE)
}
}

impl Visualizer for AcyclicExampleGame<'_> {
fn visualize(&self) -> Result<()> {
self.game.visualize(MODULE_STORAGE)
}
}

impl Visualizer for CyclicExampleGame<'_> {
fn visualize(&self) -> Result<()> {
self.game.visualize(MODULE_STORAGE)
}
}
Loading
Loading