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

Repair #65

Merged
merged 12 commits into from
Dec 16, 2023
20 changes: 0 additions & 20 deletions app/src/main/java/stock/App.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,10 @@
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package stock;


import stock.controller.*;
import stock.model.GameManager;
import stock.model.Market;
import stock.model.Stock;
import stock.model.User;
import stock.view.Gui;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;
public class App {
public String getGreeting() {
return "Hello World!";
}

public static void main(String[] args) {
GameController controller = new GameController();
System.out.println(new App().getGreeting());


}
}
6 changes: 2 additions & 4 deletions app/src/main/java/stock/ControllerInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@ public interface ControllerInterface {

public void userChoose(String mode);

//public void initializeState();

public void nextday();

public Market getMarket();

public User getUser();



public boolean buy(String get_name, float get_price, int value);

public boolean sell(String get_name, float get_price, int value);
Expand All @@ -40,4 +36,6 @@ public interface ControllerInterface {
public int get_user_quantity_for(String ticker);

public void set_illegal(boolean status);

public int get_days_played();
}
4 changes: 2 additions & 2 deletions app/src/main/java/stock/controller/EventRoller.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public EventRoller() {

// Collecting all capture groups & matches against the above regex pattern.
// This preliminary step first separates blocks by event type.
String pattern_str = "(?:\\[(\\w+)Events\\]\\n" + //
")(?:([\\w\\n" + //
String pattern_str = "(?:\\[(\\w+)Events\\]\\n" +
")(?:([\\w\\n" +
"\\{\\}\\s\\:\\\"\\!\\?\\'\\.\\;\\,\\-\\$]+))+";
Pattern p = Pattern.compile(pattern_str, Pattern.MULTILINE);
Matcher m = p.matcher(events_txt);
Expand Down
17 changes: 13 additions & 4 deletions app/src/main/java/stock/controller/GameController.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public GameController() {
this.illegal_event_name = "none";
}

//send the button click from the controller which creates and sets the user
public void userChoose(String mode) {
this.user = new User(gm.get_avg());

Expand Down Expand Up @@ -80,10 +81,10 @@ public boolean sell(String ticker, float price, int amount) {
return user.sellStock(ticker, price, amount);
}


public void nextday() {
// Rolls the event roller which produces events which will be processed this turn
ArrayList<String> currentEvents = roller.roll_out();
System.out.println("Turn events: " + currentEvents); // TODO debugging
System.out.println("Turn events: " + currentEvents);
this.user_event_name = currentEvents.get(1);
this.market_event_name = currentEvents.get(0);
if (this.roll_illegal_flag) {
Expand All @@ -95,26 +96,28 @@ public void nextday() {
this.user_event_name = (user.process_event(currentEvents.get(1))) ? this.user_event_name : "none";
game.update();

user.increaseStress(2);

// can use this to show how far the player lasted
this.day += 1;

}


public ArrayList<String> userstocknames() {
//produces a list of the current stocks that the user owns
ArrayList<String> names = new ArrayList<>();
for (String stock_name : user.get_user_stocks().keySet()) {
names.add(stock_name);
}

return names;
}

public ArrayList<Float> userstockprice() {
//produces a list of the current prices of the stocks that the user owns
ArrayList<Float> prices = new ArrayList<Float>();
HashMap<String, Integer> stocks = user.get_user_stocks();
float price = 0;

if (stocks != null) {
for (String stockName : stocks.keySet()) {
price = gm.get_market_price(stockName);
Expand All @@ -126,6 +129,7 @@ public ArrayList<Float> userstockprice() {
}

public ArrayList<Integer> userstockamount() {
//produces a list of the current amount of the stocks that the user owns
ArrayList<Integer> amount = new ArrayList<Integer>();
HashMap<String, Integer> stocks = user.get_user_stocks();
int value = 0;
Expand Down Expand Up @@ -157,6 +161,7 @@ public void set_illegal(boolean status) {
}

public String get_event_description(){
// outputs a string that is sent to the GUI to be display to the user
String event_str = new String();
event_str += "User: \n" + roller.get_description_for(this.user_event_name) + "\n\n";
event_str += "Market: \n" + roller.get_description_for(this.market_event_name) + "\n\n";
Expand All @@ -174,5 +179,9 @@ public void currentDebt(){
public int get_user_quantity_for(String ticker) {
return this.user.get_quantity_for(ticker);
}

public int get_days_played() {
return this.day;
}
}

17 changes: 1 addition & 16 deletions app/src/main/java/stock/model/GameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,39 +41,24 @@ public float get_avg(){


public void next_day(String event){

//need to call event roller here to decide what event occur,
//this will help add weights to algorithm based on events

float modify = 0;

switch(event) {
case "crash":
// code block
modify = -market.get_average_stock_price()/10;
break;
case "boom":
// code block
modify = market.get_average_stock_price()/10;
break;
default:
// code block
}
market.change_stocks(modify);
}


/* private void stock_changer(float modify, Stock stock){
double rand_double = rand.nextDouble(1);
float current_price = stock.get_price();
int current_stability = stock.get_stability();
int sign = (rand.nextFloat(0,1) <= .52)? 1 : -1;
//will fill out with more weights as we go
float new_price = modify + (float) ( current_price + (sign *current_stability * (current_price * (rand_double))));

stock.set_price(new_price);
} */

public Market getMarket() {
return this.market;
}
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/stock/model/Market.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ private void stock_changer(float modify, Stock stock) {
// per change_stocks, but for each individual stock
double rand_double = rand.nextDouble(1);
float current_price = stock.get_price();
int current_stability = stock.get_stability();
int sign = (rand.nextFloat(0,1) <= .52)? 1 : -1;
//will fill out with more weights as we go
float new_price = modify + (float) ( current_price + (sign * (current_price * (rand_double))));
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/stock/model/Stock.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public Stock(String name, String type, int id, float price) {
this.type = type;
this.id = id;
this.price = price;

// TODO -- improve/specify random behavior
Random rnd = new Random();
rnd.setSeed(1234567890);
this.stability = rnd.nextInt();
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/stock/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ public boolean buyStock(String ticker, float price, int quantity) {
if (!this.stocks.containsKey(ticker)) {
this.stocks.put(ticker, quantity);
} else {
// this.stocks.replace(ticker, this.stocks.get(ticker) + quantity);
this.stocks.put(ticker, quantity + this.stocks.get(ticker));
}
this.capital -= price * quantity;
Expand Down
Loading