Skip to content

Instantly share code, notes, and snippets.

@vinimonteiro
vinimonteiro / mcsbasketball_rule.py
Created November 24, 2020 12:20
Monte Carlo Simulation in Basketball - Take the three or quick two, considering away from the ball foul
import random
trials = 10000
three_pc = 25
two_pc = 60
opp_two_pc = 65
opp_ft_pc = 80
opp_bad_ft_pc = 40
time_to_shoot_two = 5
time_to_foul = 5
@vinimonteiro
vinimonteiro / mcsbasketball.py
Created November 24, 2020 12:21
Monte Carlo Simulation in Basketball - Take the three or quick two
import random
trials = 10000
three_pc = 25
two_pc = 60
opp_two_pc = 65
opp_ft_pc = 65
time_to_shoot_two = 5
time_to_foul = 5
offense_rb_pc = 25
@vinimonteiro
vinimonteiro / index.html
Created November 24, 2020 12:22
Data sonification service client / index.html
<HTML>
<HEAD>
<TITLE>Sonification Service</TITLE>
<script src='WebAudioFontPlayer.js'></script>
<script src='MIDIFile.js'></script>
</HEAD>
<BODY onload="onPageLoad()">
<H1>Data</H1>
<DIV ID="dataDiv">
</DIV>
@vinimonteiro
vinimonteiro / Controller.java
Created November 24, 2020 12:23
Data sonification service controller
package com.logmonitor.controller;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.Base64;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@vinimonteiro
vinimonteiro / snippet_rule.py
Created November 24, 2020 12:27
Logic responsible for handling away-from-the-ball-rule
if bad_ft_shooter_with_ball >= random.randint(0,100):
if opp_bad_ft_pc >= random.randint(0,100):
points_down += 1
if opp_bad_ft_pc >= random.randint(0,100):
points_down += 1
have_ball = True
elif ft_rb_pc >= random.randint(0,100):
have_ball = True
else:
# RULE: one free throw and no option for rebound and the ball remains with winning team.
@vinimonteiro
vinimonteiro / Minimax.java
Last active December 21, 2020 22:33
Minimax tree search
public static void main(String[] args) {
Tree tree = initialise();
System.out.println(minimax(tree.getRoot(), 2, true));
}
private static int minimax(Node node, int depth, boolean isMax) {
if(depth==0 || node.getChildren()==null || node.getChildren().isEmpty()) {
return getStateScore(); //evaluation function
}
int bestValue = Integer.MIN_VALUE;
@vinimonteiro
vinimonteiro / MinimaxAlphaBeta.java
Created December 21, 2020 22:36
Minimax Alpha-Beta Pruning
public static void main(String[] args) {
Tree tree = initialise();
System.out.println(minimax(tree.getRoot(), 2,
Integer.MIN_VALUE, Integer.MAX_VALUE, true));
}
private static int minimax(Node node, int depth, int alpha, int beta, boolean isMax) {
if(depth==0 || node.getChildren()==null || node.getChildren().isEmpty()) {
return getStateScore(); //evaluation function
}
@vinimonteiro
vinimonteiro / pom.xml
Created January 24, 2021 19:46
Sample application using Springdocs-openapi and grommet-swagger-spring
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.5.RELEASE</version>
</parent>
<groupId>com.vinimo.product.service</groupId>
@vinimonteiro
vinimonteiro / application.properties
Created January 24, 2021 21:26
grommet-swagger-spring possible parameters
#None of these properties are required. There are default values if not provided.
#If embedded in another application, the values are taken from there, from the application application.properties
#If not provided, theme=grommet
grommet-swagger.theme=hpe
#If not provided, open-api-url-path=/v3/api-docs
grommet-swagger.open-api-url-path=/v3/api-docs
#If not provided, route-prefix=grommet-swagger
@vinimonteiro
vinimonteiro / spring.factories
Created February 1, 2021 18:07
Location to enable auto configuration in Spring
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.vinimo.utility.service.controller.UtilityServiceController