id
stringlengths
36
36
text
stringlengths
1
1.25M
6f236ce7-c110-453c-af7c-e179f50a2d73
public void brew() { }
82d6e504-78f0-478d-9d31-9259a0c62ecc
void on();
7fd7946d-b9af-4814-99d4-cd3389cc8ccb
void off();
a43375bc-87d3-4e84-b887-5622fcd78ffe
boolean isHot();
60b70d87-6356-49e8-8412-fa9eef15e8d2
void pump();
9b4e9583-c105-4603-adb9-b78d4976f552
@Override public void pump() { }
91355a6d-08b9-4440-b22f-9948da8e496b
@Override public void run() { }
7096ff45-1412-436c-b490-e0be0b3b6651
public static void main(String[] args) { }
c97d46ea-36ae-48ba-9f84-01f204e532d1
@Override public void on() { }
d01adb08-168f-4884-a6f9-6bc144ca7d64
@Override public void off() { }
ef2b8fc8-3aa6-4c27-9c67-2b61079f6f8e
@Override public boolean isHot() { return false; }
bef2bd62-8cd1-41d6-8069-cd12db317abd
@Before public void setup() { // Here if you need it }
c57bc807-cb34-4e64-a6ed-f122035f1b8f
@Test public void pump_shouldPrintPumping_whenHeaterIsHot() { }
dbee4def-f583-442d-bdd5-2e3e555bf2e7
@Test public void pump_shouldNotPrintAnything_whenHeaterIsNotHot() { }
0b88d175-7cec-45b3-bc85-bc87f91841c3
@Test public void brew_shouldBrewCoffee() { }
43c4c0de-f8ef-41d0-a4ef-c0899b2d505a
@Before public void setup() { // Here if you need it }
269d62ab-eef9-46a4-bc85-a8b5c952af9a
@Test public void run_shouldBrewCoffee() { }
333fef89-c0ad-48b9-83c6-de41dbc6d28b
@Before public void setup() { // Here if you need it }
0f9c33db-ee56-464f-9744-8fd7d5ddf61a
@Test public void on_shouldPrintHeating() { }
ddde10e4-473e-446e-b096-515910b0f290
@Test public void isHot_shouldBeTrue_whenHeaterIsOn() { }
7323632c-e026-408c-82f7-f7b37a97657d
@Test public void isHot_shouldBeFalse_whenHeaterIsOff() { }
ab31e7d5-83d3-42a6-8456-54680b333c41
public String getLastPrintedStatement() { return outputStream.toString(); }
0443160e-d8e7-490d-b0a2-aa18d54b3b74
@Before public void setupTestBase() { MockitoAnnotations.initMocks(this); outputStream = new ByteArrayOutputStream(); System.setOut(new PrintStream(outputStream)); }
d360b33c-2df6-45a5-bccf-1e1026e4f847
@After public void tearDownTestBase() { System.setOut(null); }
40402241-cff3-4356-809c-80344129f472
public static Hashtable<String, Team> parseTeams(Reader reader, Collection<Stat> stats) { CSVReader csvReader = new CSVReader(reader); return parseStats(csvReader, stats); }
9b98d618-eb43-4cbd-8170-59225acfc62f
private static Hashtable<String, Team> parseStats(CSVReader reader, Collection<Stat> stats) { Hashtable<String, Team> teams = new Hashtable<String, Team>(); List<String[]> lines; try { lines = reader.readAll(); } catch (IOException e) { System.out.println("Error reading the CSV file."); return null; } for (int i = 0; i < lines.size(); i++) { String[] tokens = lines.get(i); if (tokens.length == 1 && !tokens[0].trim().equals("")) { // If this is a single token for (Stat stat : stats) { // Check all the stats if (stat.table.equals(tokens[0])) { // And see if this table has that stat int j = i + 1; for (; j < lines.size(); j++) if (lines.get(j)[0].equalsIgnoreCase("Rank")) break; String[] columnTitles = lines.get(j); int columnIndex = findColumnIndex(columnTitles, stat.column); j++; while (true) { String[] values = lines.get(j); if ((values.length == 1 && values[0].trim().length() == 0) || values[0].equals("Reclassifying")) break; Team team = getTeam(teams, values[1]); team.stats.put(stat.name, Double.parseDouble(values[columnIndex])); j += 1; } } } } } return teams; }
13c37b77-a5be-439c-85c6-f75ac272d156
private static Team getTeam(Hashtable<String, Team> teams, String name) { Team team = teams.get(name); if (team == null) { team = new Team(name); teams.put(name, team); } return team; }
31b3bab1-0c1e-4e3d-bf6e-e5ebcf729d4d
private static int findColumnIndex(String[] columns, String column) { for (int i = 0; i < columns.length; i++) if (columns[i].equals(column)) return i; return -1; }
49df72d1-3e4d-4158-ba94-f6c9d20bf6d3
public Stat(String table, String column, String name) { this.table = table; this.column = column; this.name = name; }
60a04a1d-c4de-4e4b-b574-52999cc555b9
public String toString() { return name; }
00cc580a-ca1a-4cc7-9fd0-5799ce24f3aa
public static Round parseFirstRound(Reader reader, Hashtable<String, Team> teams) throws Exception { Round games = new Round(); CSVReader csvReader = new CSVReader(reader); List<String[]> lines; try { lines = csvReader.readAll(); } catch (IOException e) { System.out.println("Error reading the CSV file."); return null; } for (String[] tokens : lines) { if (tokens.length == 1 && tokens[0].trim().length() == 0) continue; Team[] gameTeams = new Team[2]; gameTeams[0] = teams.get(tokens[0]); gameTeams[1] = teams.get(tokens[1]); if (gameTeams[0] == null) throw new Exception("Team not found: " + tokens[0]); if (gameTeams[1] == null) throw new Exception("Team not found: " + tokens[1]); if (tokens.length >= 4) { gameTeams[0].seed = Integer.parseInt(tokens[2]); gameTeams[1].seed = Integer.parseInt(tokens[3]); } for (int i = 0; i < 2; i++) if (gameTeams[i] == null) throw new Exception("Team not found: " + tokens[i]); Game game = new Game(gameTeams); game.name = String.format("R0 G%d", games.size()); games.add(game); } return games; }
ee4edce8-a08e-444f-88e6-d78c4ad6b13e
public static Hashtable<String, CompiledStat> compileStats(Vector<Stat> stats, Collection<Team> teams) { Vector<Team> teamVector = new Vector<Team>(teams); Hashtable<String, CompiledStat> compiledStats = new Hashtable<String, CompiledStat>(); for (Stat stat : stats) { double[] values = new double[teams.size()]; for (int i = 0; i < teams.size(); i++) { Team team = teamVector.get(i); values[i] = team.getStat(stat.name); } compiledStats.put(stat.name, new CompiledStat(stat.name, values)); } return compiledStats; }
1cdd3745-7fe2-46a6-9bc7-4b5c74c6c9c8
public Tournament(Round firstRound, Hashtable<String, CompiledStat> compiledStats, Referee scoreable) { if (md5 == null) { try { md5 = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } } this.compiledStats = compiledStats; this.scoreable = scoreable; Round duplicate = new Round(); for (Game game : firstRound) { Game dupeGame = new Game(game.teams, scoreable); dupeGame.name = game.name; duplicate.add(dupeGame); } rounds.add(duplicate); appendNextRound(duplicate); }
74d2df0d-4146-4fcf-9dea-4eded8d0bacb
public void appendNextRound(Round round) { Round nextRound = new Round(); rounds.add(nextRound); int roundNumber = rounds.indexOf(nextRound); int gameCount = 0; for (int i = 0; i < round.size(); i += 2) { Game newGame = new Game(); newGame.referee = scoreable; Game[] previousGames = new Game[] { round.get(i), round.get(i + 1) }; for (Game previousGame : previousGames) previousGame.nextGame = newGame; newGame.previousGames = previousGames; newGame.name = String.format("R%d G%d", roundNumber, gameCount); nextRound.add(newGame); gameCount++; } if (nextRound.size() == 1) return; appendNextRound(nextRound); }
361efa41-2cb0-47e8-acfa-031ed5e2c944
public Team play() { return play(rounds.get(0)); }
a5f7b88a-ebeb-4a88-9e62-24ac403cf915
private Team play(Round round) { for (Game game : round) { game.compiledStats = compiledStats; Team winner = game.play(); if (round.size() == 1) return winner; game.nextGame.addTeam(winner); } return play(rounds.get(rounds.indexOf(round) + 1)); }
7f1367e5-1c2c-4b6c-b203-9785d84fa17f
public String toPrintableString() { StringBuilder builder = new StringBuilder(); int maxNameLength = 0; for (Game game : rounds.get(0)) maxNameLength = Math.max(Math.max(game.teams[0].toString().length(), game.teams[1].toString().length()), maxNameLength); int columnWidth = maxNameLength + COLUMN_PADDING + COLUMN_PREFIX_MARGIN + COLUMN_SUFFIX_MARGIN; for (int line = 0; line < PRINT_HEIGHT; line++) { for (int round = 0; round < rounds.size(); round++) { if (round == 0) builder.append(teamAt(line, round, columnWidth - COLUMN_PREFIX_MARGIN)); else builder.append(teamAt(line, round, columnWidth)); } builder.append("\n"); } return builder.toString(); }
1b162f83-837c-4368-aed3-f7a6f48dc971
private String teamAt(int line, int roundNumber, int columnWidth) { Round round = rounds.get(roundNumber); Team team = null; String teamName = ""; int teamScore = 0; int linesPerGame = PRINT_HEIGHT / round.size(); int lineGame = (int)Math.floor((double)line / (double)linesPerGame); int startLine = lineGame * linesPerGame; int bottomGameLine = startLine + linesPerGame / 2; int topGameLine = bottomGameLine - 1; Game game = round.get(lineGame); if (line == topGameLine) { team = game.teams[0]; if (roundNumber > 0) teamName += "\\ "; teamScore = (int)game.scores[0]; } else if (line == bottomGameLine) { team = round.get(lineGame).teams[1]; if (roundNumber > 0) teamName += "/ "; teamScore = (int)game.scores[1]; } if (team != null) { teamName += team.toString(); teamName += String.format(" - %d", teamScore); if (team == game.winner) { teamName += " <"; if (game.winner.seed > game.loser.seed) teamName += "<<"; } } int end = teamName.length() == 0 ? columnWidth - EMPTY_ROW_PULL * roundNumber : columnWidth; for (int i = teamName.length(); i < end; i++) teamName += " "; return teamName; }
aa6144fc-3d7b-476d-8710-fa95bd1ae604
public String toSummaryString() { StringWriter stringWriter = new StringWriter(); CSVWriter writer = new CSVWriter(stringWriter); String[] columns = new String[0]; for (Round round : rounds) { for (Game game : round) { for (int i = 0; i < 2; i++) { if (columns.length == 0) { if (game.summaryStats.size() == 0) return ""; columns = game.summaryStats.toArray(columns); writer.writeNext(columns); } String[] values = new String[columns.length]; for (int j = 0; j < values.length; j++) values[j] = game.summaries[i].get(columns[j]).toString(); writer.writeNext(values); } } } return stringWriter.toString(); }
b7abf633-88f0-4da4-a291-0dddd4967f90
public byte[] getHash() { String id = this.rounds.toString(); return md5.digest(id.getBytes()); }
fcf9f5cf-e8f2-435f-9f9e-0c758337200c
public Team getWinner() { return rounds.lastElement().get(0).winner; }
0cc2f601-98fd-4b82-a71c-e45faafdaaed
public CompiledStat(String name, double[] values) { this.name = name; computeStats(values); }
e68e9a83-13d7-42f6-9f7f-9412b0f26091
private void computeStats(double[] values) { double sum = 0.0; min = values[0]; max = values[0]; for (double value : values) { sum += value; min = Math.min(min, value); max = Math.max(max, value); } mean = sum / (double)values.length; dev = calculateDev(values); }
ef71bb47-3449-4a6d-b87b-aea767c16460
private double calculateDev(double[] values) { return Math.pow(calculateVar(values), 0.5); }
1c2bbec3-9c8c-4ccd-a403-9d2b717e94f3
static double calculateVar(double[] values) { double total = 0.0; double sTotal = 0.0; double scalar = 1.0/(double)(values.length - 1); for (int i = 0; i < values.length; i++) { total += values[i]; sTotal += Math.pow(values[i], 2); } return (scalar * (sTotal - (Math.pow(total, 2) / values.length))); }
c8cf2002-49af-4839-af24-c993830e757d
public String toString() { return name; }
ccc3d7da-ee1a-47f4-97b7-63f28cd0ce9e
public Team play() { referee.playGame(this); return winner; }
0e9df48f-abac-4341-b361-ac452de405ab
public Game() {};
e3daea68-ddc9-4e73-9640-85419546491d
public Game(Team[] teams) { this.teams = teams; }
2d7e7694-8332-41e4-832c-8b012c2c8573
public Game(Team[] teams, Referee scoreable) { this(teams); this.referee = scoreable; }
81636b37-2c4b-473a-ad3e-e1ae53e75fd6
public void addTeam(Team team) { for (int i = 0; i < teams.length; i++) { if (teams[i] == null) { teams[i] = team; return; } } }
f07f4d3f-0f21-4aa6-a91d-128b4ea95a1c
public String toString() { return String.format("%s (%s vs. %s)", name, teams[0].toString(), teams[1].toString()); }
e8362d9f-e866-444d-bd3b-e92c495e51db
public static void main(String[] args) throws Exception { if (args.length < 3 || args[0].isEmpty() || args[1].isEmpty() || args[2].isEmpty()) { System.out.println("Too few arguments. Required arguments: [year] [men|women] [referee class name]"); return; } if (!args[1].equals("men") && !args[1].equals("women")) { System.out.println("The second argument must be 'men' or 'women'."); return; } String year = args[0]; String sex = args[1]; String refereeClassName = args[2]; Referee referee; try { referee = (Referee) Class.forName("bracketeer.referees." + refereeClassName).newInstance(); } catch (Exception ex) { System.out.println("The referee class '" + refereeClassName + "' was not found in the package bracketeer.referees. Check your capitalization and be sure to recompile."); return; } Vector<Stat> stats = new Vector<Stat>(); stats.add(new Stat("Division IWon-Lost Percentage", "Pct", "Win %")); stats.add(new Stat("Division IScoring Margin", "PPG", "PPG")); stats.add(new Stat("Division IScoring Margin", "OPP PPG", "OPP PPG")); stats.add(new Stat("Division IScoring Margin", "SCR MAR", "SCR MAR")); stats.add(new Stat("Division IRebound Margin", "RPG", "RPG")); stats.add(new Stat("Division IField-Goal Percentage", "FG%", "FG%")); stats.add(new Stat("Division IField-Goal Percentage", "FGA", "FGA")); stats.add(new Stat("Division IField-Goal Percentage Defense", "OPP FG", "OPP FG")); stats.add(new Stat("Division IField-Goal Percentage Defense", "OPP FGA", "OPP FGA")); stats.add(new Stat("Division IField-Goal Percentage Defense", "OPP FG%", "OPP FG%")); stats.add(new Stat("Division IPersonal Fouls Per Game", "PFPG", "PFPG")); stats.add(new Stat("Division IFree-Throw Percentage", "FT%", "FT%")); stats.add(new Stat("Division IFree-Throw Percentage", "FTA", "FTA")); stats.add(new Stat("Division IBlocked Shots Per Game", "BKPG", "BKPG")); stats.add(new Stat("Division ISteals Per Game", "STPG", "STPG")); stats.add(new Stat("Division ITurnovers Per Game", "TOPG", "TOPG")); stats.add(new Stat("Division ITurnover Margin", "Opp TO", "OPP TOPG")); stats.add(new Stat("Division IAssists Per Game", "APG", "APG")); stats.add(new Stat("Division IThree Pt FG Defense", "Pct", "OPP 3FG%")); stats.add(new Stat("Division IThree-Point Field-Goal Percentage", "3FG%", "3FG%")); stats.add(new Stat("Division IThree-Point Field-Goal Percentage", "3FGA", "3FGA")); stats.add(new Stat("Division IThree-Point Field-Goal Percentage", "GM", "GM")); if (args[1].equals("women")) { stats.add(new Stat("Division ITurnover Margin", "Margin", "TO RATIO")); } else { stats.add(new Stat("Division ITurnover Margin", "Ratio", "TO RATIO")); } String rankingsFileName = "seasons/" + year + "/rankings_" + sex + ".csv"; String firstRoundFileName = "seasons/" + year + "/firstround_" + sex + ".csv"; String outputFileName = "results/" + refereeClassName + ".csv"; new File("results").mkdir(); Hashtable<String, Team> teams = Parser.parseTeams(new FileReader(rankingsFileName), stats); Round firstRound = Parser.parseFirstRound(new FileReader(firstRoundFileName), teams); Vector<Team> firstRoundTeams = new Vector<Team>(); for (Game game : firstRound) { firstRoundTeams.add(game.teams[0]); firstRoundTeams.add(game.teams[1]); } //Hashtable<String, CompiledStat> compiledStats = Parser.compileStats(stats, firstRoundTeams); // To play one game: Tournament t = new Tournament(firstRound, null, referee); t.play(); System.out.print(t.toPrintableString()); FileWriter writer = new FileWriter(outputFileName); writer.write(t.toSummaryString()); writer.close(); // To play many games: /*Hashtable<String, Tournament> tourneys = new Hashtable<String, Tournament>(); for (int i = 0 ; i < TRIALS; i++) { Tournament t = new Tournament(firstRound, compiledStats, scoreable); Team winner = t.play(); winner.wins++; tourneys.put(new String(t.getHash()), t); } Vector<Team> sortedTeams = new Vector<Team>(teams.values()); Collections.sort(sortedTeams, new TopWins()); System.out.println("\nSample bracket from the winningest team:\n"); for (Tournament t : tourneys.values()) { if (t.getWinner() == sortedTeams.firstElement()) { System.out.print(t.toPrintableString()); break; } } System.out.printf("\n%d tourneys were duplicates\n\n", TRIALS - tourneys.size()); System.out.println("Wins out of " + TRIALS + ":\n"); for (Team team : sortedTeams) if (team.wins > 0) System.out.printf("%s: %d\n", team.toString(), team.wins); */ }
c1004516-cd05-41f1-95b1-f4f00725c7e8
public int compare(Team o1, Team o2) { if (o1.wins > o2.wins) return -1; else if (o1.wins < o2.wins) return 1; else return 0; }
d586efa1-f8ac-4cbc-ad23-691907eff0d3
public Team(String name) { this.name = name; }
ce89f39d-3fc1-4051-9ff6-4d4cd4ea9c9e
public Team(String name, int seed) { this.name = name; this.seed = seed; }
79ad7982-3f07-4051-8d56-4ccbcddea060
public String toString() { if (seed >= 10) return String.format("%d %s", seed, name); else if (seed > 0) return String.format(" %d %s", seed, name); else return name; }
8a7303ef-6db8-4694-9914-812afea69afa
public Double getStat(String stat) { return this.stats.get(stat); }
d2c62349-a16e-417f-9596-fbea4ef9ad36
public void playGame(Game game) { game.summaries[0] = new Hashtable<String, String>(); game.summaries[1] = new Hashtable<String, String>(); game.summaryStats.add("Game"); game.summaries[0].put("Game", game.name); game.summaries[1].put("Game", game.name); game.summaryStats.add("Team"); game.summaryStats.add("BASE PTS"); game.summaryStats.add("FG BONUS"); game.summaryStats.add("WIN BONUS"); game.summaryStats.add("TO PTS"); game.summaryStats.add("TO PTS LOST"); game.summaryStats.add("PF PTS"); game.summaryStats.add("RB PTS"); game.summaryStats.add("BLK PTS"); game.summaryStats.add("PTS"); game.scores[0] = calculateScore(game.teams[0], game.teams[1], game.compiledStats, game.summaries[0]); game.scores[1] = calculateScore(game.teams[1], game.teams[0], game.compiledStats, game.summaries[1]); if (game.scores[0] > game.scores[1]) { game.winner = game.teams[0]; game.loser = game.teams[1]; } else { game.winner = game.teams[1]; game.loser = game.teams[0]; } }
0b55f556-618e-43c2-9d10-ca5d765e9b9e
private Double calculateScore(Team home, Team away, Hashtable<String, CompiledStat> compiledStats, Hashtable<String, String> summary) { // Base score (30% weight) Double basePts = 0.4 * (0.4 * home.getStat("PPG") + 0.6 * away.getStat("OPP PPG")); Double pts = basePts; // Shooting bonus Double fgBonus = basePts * home.getStat("FG%") * 0.01; pts += fgBonus; // Win bonus (10% of the base points for 100%) Double winBonus = 0.1 * basePts * home.getStat("Win %") * 0.01; pts += winBonus; // Turnovers (gain 2 points for each out-turnover and lose 2 the same way) Double turnoverLostPoints = -2.0 * (home.getStat("TOPG") + away.getStat("STPG")); pts += turnoverLostPoints; Double turnoverGainedPoints = 2.0 * (home.getStat("STPG") + away.getStat("TOPG")); pts += turnoverGainedPoints; // Personal fouls (gain 2 points per PF at FT%) Double pfPts = 2 * home.getStat("FT%") * 0.01 * away.getStat("PFPG"); pts += pfPts; // Rebounds (gain 2 points for each out-rebound) Double reboundPts = 2.0 * (home.getStat("RPG") - away.getStat("RPG")); pts += reboundPts; // Block (gain 2 points for each out-block) Double blockPts = 2.0 * (home.getStat("BKPG") - away.getStat("BKPG")); pts += blockPts; // Summarize summary.put("BASE PTS", basePts.toString()); summary.put("FG BONUS", fgBonus.toString()); summary.put("WIN BONUS", winBonus.toString()); summary.put("TO PTS", turnoverGainedPoints.toString()); summary.put("TO PTS LOST", turnoverLostPoints.toString()); summary.put("PF PTS", pfPts.toString()); summary.put("RB PTS", reboundPts.toString()); summary.put("BLK PTS", blockPts.toString()); summary.put("PTS", pts.toString()); summary.put("Team", home.toString()); return pts; }
801c9cc5-df5b-4173-96d8-437aa36f267a
private double randomAbout(double range) { double sign = (Math.random() - 0.5); sign = (sign < 0 ? -1 : 1); return sign * range; }
04e3c961-f70f-460d-8882-41d147ff9449
private double randomRange(double start, double end) { return Math.random() * (end - start) + start; }
d4bac56b-2ab5-4042-bff8-3159905a0206
public void playGame(Game game) { game.scores[0] = calculateScore(game.teams[0], game.teams[1], game.compiledStats); game.scores[1] = calculateScore(game.teams[1], game.teams[0], game.compiledStats); if (game.scores[0] > game.scores[1]) { game.winner = game.teams[0]; game.loser = game.teams[1]; } else { game.winner = game.teams[1]; game.loser = game.teams[0]; } }
e70fcb04-5a8a-480d-ae57-ce783514a2d8
private double calculateScore(Team home, Team away, Hashtable<String, CompiledStat> compiledStats) { // Base expected score double baseScore = (0.5) * (1.0 * home.getStat("PPG") + 1.0 * away.getStat("OPP PPG")) / 2.0; double score = baseScore + randomAbout(baseScore * VARIABILITY); // Give a bonus for having wins double winBonus = (0.4) * (home.getStat("Win %")); score += winBonus + randomAbout(winBonus * VARIABILITY); // Decrease the score by the opponent's scoring margin double scoringMarginMargin = away.getStat("SCR MAR") - home.getStat("SCR MAR"); double scoringMarginPoints = 0.7 * scoringMarginMargin + randomAbout(scoringMarginMargin * VARIABILITY); score -= scoringMarginPoints; // Turnovers double turnoverPoints = 0.4 * (home.getStat("TOPG") + away.getStat("STPG")); score -= turnoverPoints * randomAbout(turnoverPoints * VARIABILITY); // Personal fouls double pfPoints = 1.5 * home.getStat("FT%") * 0.01 * away.getStat("PFPG"); score += pfPoints + randomAbout(pfPoints * VARIABILITY); double reboundDiff = home.getStat("RPG") - away.getStat("RPG"); score += 1 * reboundDiff + randomAbout(reboundDiff * VARIABILITY); double opponentBlocks = 1 * away.getStat("BKPG"); score -= opponentBlocks + randomAbout(opponentBlocks * VARIABILITY); return score; }
49bb829f-81c7-4a13-a4df-c9c5f4ec82fd
private double randomAbout(double range) { double sign = (Math.random() - 0.5); sign = (sign < 0 ? -1 : 1); return sign * range; }
7bb57925-2082-4b4e-93cc-75de539726a2
public void playGame(Game game) { // Potential possession outcomes: // Made 2FG // Made 3FG // Missed 2FG // Missed 3FG // Offensive foul // Defensive foul // Turnover TeamStatus[] status = new TeamStatus[2]; status[0] = new TeamStatus(); status[1] = new TeamStatus(); int timeLeft = SEC_PER_GAME; // 40 minutes int offenseTeamIndex = _rand.nextInt(1); // Tip-off while (true) { if (timeLeft < 0) break; Team offense = game.teams[offenseTeamIndex]; Team defense = game.teams[(offenseTeamIndex + 1) % 2]; TeamStatus offenseStatus = status[offenseTeamIndex]; TeamStatus defenseStatus = status[(offenseTeamIndex + 1) % 2]; int possessionLength = (int)constrain(gaussian(20, 5), 5, 35); boolean shotMade = false; // Call a timeout if opponent has too much momentum if (defenseStatus.momentum > 3 && offenseStatus.timeOuts > 0) { offenseStatus.timeOuts--; offenseStatus.momentum = 1; defenseStatus.momentum = 1; } double turnoverPercent = (offense.getStat("TOPG") + defense.getStat("STPG")) / 2.0 / POSS_PER_GAME; if (happens(turnoverPercent)) { // Turnover; no shot made possessionLength /= 2; } else { // Attempt a shot // First determine type of shot (FG or 3FG) int shotTypeSum, shotTypeValue; if (offense.getStat("3FGA") == null) { // Force FG shotTypeValue = 0; shotTypeSum = 1; } else { shotTypeSum = offense.getStat("FGA").intValue() + offense.getStat("3FGA").intValue(); shotTypeValue = _rand.nextInt(shotTypeSum); } if (shotTypeValue < offense.getStat("FGA")) { // FG attempt for (int i = 0; i < offenseStatus.momentum / 2; i++) { double shotPercent = (offense.getStat("FG%") + defense.getStat("OPP FG%")) / 2.0 / 100.0; if (happens(shotPercent)) { // FG made offenseStatus.points += 2; offenseStatus.momentum += 1; defenseStatus.momentum = Math.max(1, defenseStatus.momentum - 1); shotMade = true; break; } } } else { // 3FG attempt for (int i = 0; i < offenseStatus.momentum / 2; i++) { double shotPercent = (offense.getStat("3FG%") + defense.getStat("OPP 3FG%")) / 2.0 / 100.0; if (happens(shotPercent)) { // 3FG made offenseStatus.points += 3; offenseStatus.momentum += 2; defenseStatus.momentum = Math.max(1, defenseStatus.momentum - 1); shotMade = true; break; } } } } if (!shotMade) { // Decrement momentum offenseStatus.momentum = Math.max(1, offenseStatus.momentum - 1); } timeLeft -= possessionLength; if (timeLeft <= HALFTIME && timeLeft + possessionLength >= HALFTIME) { // Halftime! offenseStatus.timeOuts = 5; offenseStatus.momentum = 1; offenseStatus.halfFouls = 0; defenseStatus.timeOuts = 5; defenseStatus.momentum = 1; defenseStatus.halfFouls = 0; } offenseTeamIndex = (offenseTeamIndex + 1) % 2; } game.scores[0] = status[0].points; game.scores[1] = status[1].points; //playPossession(timeLeft, status, startingTeam); if (game.scores[0] > game.scores[1]) { game.winner = game.teams[0]; game.loser = game.teams[1]; } else { game.winner = game.teams[1]; game.loser = game.teams[0]; } }
bd49039d-fe8b-42a4-b540-0fe7c4db548d
private double gaussian(double mean, double stdDev) { return _rand.nextGaussian() * stdDev + mean; }
316e2b8f-e376-4b5a-afcd-7315236a32f7
private double constrain(double value, double min, double max) { if (value < min) return min; if (value > max) return max; return value; }
87430e5d-3bbd-42fe-aa14-a6a015b4cab1
private boolean happens(double percent) { // percent ranges from 0 to 1 return _rand.nextDouble() < percent; }
f12d36c7-2326-47b6-9ab8-00a370a03338
public void playGame(Game game);
8b891c45-0683-4522-a69b-e3bd85944730
public CSVReader(Reader reader) { this(reader, DEFAULT_SEPARATOR); }
8938cb11-569e-4231-b451-3411b6e1a462
public CSVReader(Reader reader, char separator) { this(reader, separator, DEFAULT_QUOTE_CHARACTER); }
67c53d6c-d868-4ab6-a953-a6899a64e9e2
public CSVReader(Reader reader, char separator, char quotechar) { this(reader, separator, quotechar, DEFAULT_SKIP_LINES); }
82428d1e-4b1b-4698-9875-3a3c45173bfc
public CSVReader(Reader reader, char separator, char quotechar, int line) { this.br = new BufferedReader(reader); this.separator = separator; this.quotechar = quotechar; this.skipLines = line; }
8dad8a77-e00c-4065-912e-3b3077300365
public List readAll() throws IOException { List allElements = new ArrayList(); while (hasNext) { String[] nextLineAsTokens = readNext(); if (nextLineAsTokens != null) allElements.add(nextLineAsTokens); } return allElements; }
6e6d5bf6-dc61-4879-a123-dfc34687fda1
public String[] readNext() throws IOException { String nextLine = getNextLine(); return hasNext ? parseLine(nextLine) : null; }
1e09b27b-dbd2-4227-98e3-27f26cefb5f9
private String getNextLine() throws IOException { if (!this.linesSkiped) { for (int i = 0; i < skipLines; i++) { br.readLine(); } this.linesSkiped = true; } String nextLine = br.readLine(); if (nextLine == null) { hasNext = false; } return hasNext ? nextLine : null; }
e1855207-da1f-4266-ae2b-17cc89ac6c3f
private String[] parseLine(String nextLine) throws IOException { if (nextLine == null) { return null; } List tokensOnThisLine = new ArrayList(); StringBuffer sb = new StringBuffer(); boolean inQuotes = false; do { if (inQuotes) { // continuing a quoted section, reappend newline sb.append("\n"); nextLine = getNextLine(); if (nextLine == null) break; } for (int i = 0; i < nextLine.length(); i++) { char c = nextLine.charAt(i); if (c == quotechar) { // this gets complex... the quote may end a quoted block, or escape another quote. // do a 1-char lookahead: if( inQuotes // we are in quotes, therefore there can be escaped quotes in here. && nextLine.length() > (i+1) // there is indeed another character to check. && nextLine.charAt(i+1) == quotechar ){ // ..and that char. is a quote also. // we have two quote chars in a row == one quote char, so consume them both and // put one on the token. we do *not* exit the quoted text. sb.append(nextLine.charAt(i+1)); i++; }else{ inQuotes = !inQuotes; // the tricky case of an embedded quote in the middle: a,bc"d"ef,g if(i>2 //not on the begining of the line && nextLine.charAt(i-1) != this.separator //not at the begining of an escape sequence && nextLine.length()>(i+1) && nextLine.charAt(i+1) != this.separator //not at the end of an escape sequence ){ sb.append(c); } } } else if (c == separator && !inQuotes) { tokensOnThisLine.add(sb.toString()); sb = new StringBuffer(); // start work on next token } else { sb.append(c); } } } while (inQuotes); tokensOnThisLine.add(sb.toString()); return (String[]) tokensOnThisLine.toArray(new String[0]); }
22818b98-f3cf-420f-9313-a354baba46e1
public void close() throws IOException{ br.close(); }
37f4c1ea-7224-4499-9edb-3082506a42ff
public CSVWriter(Writer writer) { this(writer, DEFAULT_SEPARATOR); }
014ba124-b5eb-4bb8-8fe0-06c7850e8279
public CSVWriter(Writer writer, char separator) { this(writer, separator, DEFAULT_QUOTE_CHARACTER); }
a6a2b5fe-3b3c-41c3-ac2d-6881a338d83c
public CSVWriter(Writer writer, char separator, char quotechar) { this(writer, separator, quotechar, DEFAULT_ESCAPE_CHARACTER); }
280b3078-3b46-4e09-92c4-b81d34cde6c1
public CSVWriter(Writer writer, char separator, char quotechar, char escapechar) { this(writer, separator, quotechar, escapechar, DEFAULT_LINE_END); }
2fe681f1-5670-431d-87f5-442107e9c1be
public CSVWriter(Writer writer, char separator, char quotechar, String lineEnd) { this(writer, separator, quotechar, DEFAULT_ESCAPE_CHARACTER, lineEnd); }
03bb1243-5dbc-412f-8296-1c204c1602ba
public CSVWriter(Writer writer, char separator, char quotechar, char escapechar, String lineEnd) { this.rawWriter = writer; this.pw = new PrintWriter(writer); this.separator = separator; this.quotechar = quotechar; this.escapechar = escapechar; this.lineEnd = lineEnd; }
76e68560-8d8b-4268-9bd2-5c7ea8842925
public void writeAll(List allLines) { for (Iterator iter = allLines.iterator(); iter.hasNext();) { String[] nextLine = (String[]) iter.next(); writeNext(nextLine); } }
8a2f292d-179b-4018-83d4-8351be6ddf8b
protected void writeColumnNames(ResultSetMetaData metadata) throws SQLException { int columnCount = metadata.getColumnCount(); String[] nextLine = new String[columnCount]; for (int i = 0; i < columnCount; i++) { nextLine[i] = metadata.getColumnName(i + 1); } writeNext(nextLine); }
eeed4cf8-ec15-4c13-a8fe-e669d9a6aff1
public void writeAll(java.sql.ResultSet rs, boolean includeColumnNames) throws SQLException, IOException { ResultSetMetaData metadata = rs.getMetaData(); if (includeColumnNames) { writeColumnNames(metadata); } int columnCount = metadata.getColumnCount(); while (rs.next()) { String[] nextLine = new String[columnCount]; for (int i = 0; i < columnCount; i++) { nextLine[i] = getColumnValue(rs, metadata.getColumnType(i + 1), i + 1); } writeNext(nextLine); } }
157223fe-acb3-4c3a-bf4b-71544fe962d6
private static String getColumnValue(ResultSet rs, int colType, int colIndex) throws SQLException, IOException { String value = ""; switch (colType) { case Types.BIT: Object bit = rs.getObject(colIndex); if (bit != null) { value = String.valueOf(bit); } break; case Types.BOOLEAN: boolean b = rs.getBoolean(colIndex); if (!rs.wasNull()) { value = Boolean.valueOf(b).toString(); } break; case Types.CLOB: Clob c = rs.getClob(colIndex); if (c != null) { value = read(c); } break; case Types.BIGINT: case Types.DECIMAL: case Types.DOUBLE: case Types.FLOAT: case Types.REAL: case Types.NUMERIC: BigDecimal bd = rs.getBigDecimal(colIndex); if (bd != null) { value = "" + bd.doubleValue(); } break; case Types.INTEGER: case Types.TINYINT: case Types.SMALLINT: int intValue = rs.getInt(colIndex); if (!rs.wasNull()) { value = "" + intValue; } break; case Types.JAVA_OBJECT: Object obj = rs.getObject(colIndex); if (obj != null) { value = String.valueOf(obj); } break; case Types.DATE: java.sql.Date date = rs.getDate(colIndex); if (date != null) { value = DATE_FORMATTER.format(date);; } break; case Types.TIME: Time t = rs.getTime(colIndex); if (t != null) { value = t.toString(); } break; case Types.TIMESTAMP: Timestamp tstamp = rs.getTimestamp(colIndex); if (tstamp != null) { value = TIMESTAMP_FORMATTER.format(tstamp); } break; case Types.LONGVARCHAR: case Types.VARCHAR: case Types.CHAR: value = rs.getString(colIndex); break; default: value = ""; } if (value == null) { value = ""; } return value; }
f8ada4b7-3f98-44f0-ac79-1e1259194620
private static String read(Clob c) throws SQLException, IOException { StringBuffer sb = new StringBuffer( (int) c.length()); Reader r = c.getCharacterStream(); char[] cbuf = new char[2048]; int n = 0; while ((n = r.read(cbuf, 0, cbuf.length)) != -1) { if (n > 0) { sb.append(cbuf, 0, n); } } return sb.toString(); }
a040ad75-4dc0-4b31-a955-ff1db6a32678
public void writeNext(String[] nextLine) { if (nextLine == null) return; StringBuffer sb = new StringBuffer(); for (int i = 0; i < nextLine.length; i++) { if (i != 0) { sb.append(separator); } String nextElement = nextLine[i]; if (nextElement == null) continue; if (quotechar != NO_QUOTE_CHARACTER) sb.append(quotechar); for (int j = 0; j < nextElement.length(); j++) { char nextChar = nextElement.charAt(j); if (escapechar != NO_ESCAPE_CHARACTER && nextChar == quotechar) { sb.append(escapechar).append(nextChar); } else if (escapechar != NO_ESCAPE_CHARACTER && nextChar == escapechar) { sb.append(escapechar).append(nextChar); } else { sb.append(nextChar); } } if (quotechar != NO_QUOTE_CHARACTER) sb.append(quotechar); } sb.append(lineEnd); pw.write(sb.toString()); }
b3da4eb3-ea19-41c5-bf76-f471ea491a41
public void flush() throws IOException { pw.flush(); }
0fe3a83d-9eee-475b-8203-cdd9bc96e4a4
public void close() throws IOException { pw.flush(); pw.close(); rawWriter.close(); }
afd74622-642b-4b1d-b011-2d285973cc36
public void test_tilt_line_left() { int[] expected = null; int[] old = null; int[] after = null; Game2048Core processer = new Game2048Core(); old = new int[] { 0, 0, 2, 2 }; after = processer.tilt_line_left(old); expected = new int[] { 2, 2, 0, 0 }; if (GameUtil.compareExpectToActualLine(expected, after)) { GameUtil.printLine(old, "", after, expected, GameUtil.PASSED); } else { GameUtil.printLine(old, "", after, expected, GameUtil.FAILED); fail(); } old = new int[] { 0, 0, 0, 2 }; after = processer.tilt_line_left(old); expected = new int[] { 2, 0, 0, 0 }; if (GameUtil.compareExpectToActualLine(expected, after)) { GameUtil.printLine(old, "", after, expected, GameUtil.PASSED); } else { GameUtil.printLine(old, "", after, expected, GameUtil.FAILED); fail(); } old = new int[] { 2, 0, 0, 2 }; after = processer.tilt_line_left(old); expected = new int[] { 2, 2, 0, 0 }; if (GameUtil.compareExpectToActualLine(expected, after)) { GameUtil.printLine(old, "", after, expected, GameUtil.PASSED); } else { GameUtil.printLine(old, "", after, expected, GameUtil.FAILED); fail(); } old = new int[] { 2, 0, 0, 0 }; after = processer.tilt_line_left(old); expected = new int[] { 2, 0, 0, 0 }; if (GameUtil.compareExpectToActualLine(expected, after)) { GameUtil.printLine(old, "", after, expected, GameUtil.PASSED); } else { GameUtil.printLine(old, "", after, expected, GameUtil.FAILED); fail(); } }
b297cba1-fadd-4d9f-8816-7bfe429007e5
public void test_combine_tiles() { int[] expected = null; int[] old = null; Game2048Core processer = new Game2048Core(); old = new int[] { 1, 1, 0, 0 }; int after[] = processer.combine_tiles(old); expected = new int[] { 2, 0, 0, 0 }; if (GameUtil.compareExpectToActualLine(expected, after)) { GameUtil.printLine(old, "after combine_line_left became", after, expected, GameUtil.PASSED); } else { GameUtil.printLine(old, "after combine_line_left became", after, expected, GameUtil.FAILED); fail(); } old = new int[] { 1, 1, 1, 0 }; after = processer.combine_tiles(old); expected = new int[] { 2, 1, 0, 0 }; if (GameUtil.compareExpectToActualLine(expected, after)) { GameUtil.printLine(old, "after combine_line_left became", after, expected, GameUtil.PASSED); } else { GameUtil.printLine(old, "after combine_line_left became", after, expected, GameUtil.FAILED); fail(); } old = new int[] { 1, 1, 1, 1 }; after = processer.combine_tiles(old); expected = new int[] { 2, 2, 0, 0 }; if (GameUtil.compareExpectToActualLine(expected, after)) { GameUtil.printLine(old, "after combine_line_left became", after, expected, GameUtil.PASSED); } else { GameUtil.printLine(old, "after combine_line_left became", after, expected, GameUtil.FAILED); fail(); } old = new int[] { 1, 2, 3, 4 }; after = processer.combine_tiles(old); expected = new int[] { 1, 2, 3, 4 }; if (GameUtil.compareExpectToActualLine(expected, after)) { GameUtil.printLine(old, "after combine_line_left became", after, expected, GameUtil.PASSED); } else { GameUtil.printLine(old, "after combine_line_left became", after, expected, GameUtil.FAILED); fail(); } old = new int[] { 1, 2, 3, 3 }; after = processer.combine_tiles(old); expected = new int[] { 1, 2, 6, 0 }; if (GameUtil.compareExpectToActualLine(expected, after)) { GameUtil.printLine(old, "after combine_line_left became", after, expected, GameUtil.PASSED); } else { GameUtil.printLine(old, "after combine_line_left became", after, expected, GameUtil.FAILED); fail(); } old = new int[] { 1, 2, 2, 3 }; after = processer.combine_tiles(old); expected = new int[] { 1, 4, 3, 0 }; if (GameUtil.compareExpectToActualLine(expected, after)) { GameUtil.printLine(old, "after combine_line_left became", after, expected, GameUtil.PASSED); } else { GameUtil.printLine(old, "after combine_line_left became", after, expected, GameUtil.FAILED); fail(); } }
9adcde4d-5eb7-4fd5-8794-5d52eecbc484
private boolean line_vector_test(int i1, int i2, int i3, int i4, String msg, int o1, int o2, int o3, int o4) { Game2048Core processer = new Game2048Core(); int list[] = { i1, i2, i3, i4 }; if (null != msg) { System.out.print(msg); } else { System.out.print(" Tilting " + GameUtil.convertLineToTxtWithSep(i1, i2, i3, i4) + " left yields " + GameUtil.convertLineToTxtWithSep(o1, o2, o3, o4)); } list = processer.tilt_line_left_combine(new int[] { i1, i2, i3, i4 }); if ((list[0] != o1) || (list[1] != o2) || (list[2] != o3) || (list[3] != o4)) { System.out.println(" FAILED: " + GameUtil.convertLineToTxtWithSep(i1, i2, i3, i4) + " became " + GameUtil.convertLineToTxtWithSep(list) + " instead of " + GameUtil.convertLineToTxtWithSep(o1, o2, o3, o4)); return false; } System.out.println(" - PASSED."); return true; }
c305f4a1-f4f7-4a64-b494-d25f207fa74f
public void test_tilt_left() { boolean e = true; e &= line_vector_test(0, 0, 0, 0, "Empty list is empty after shift", 0, 0, 0, 0); e &= line_vector_test(1, 0, 0, 0, "Value on left stays on left after shift", 1, 0, 0, 0); e &= line_vector_test(0, 0, 0, 1, "Value on right shifts to left edge after shift", 1, 0, 0, 0); e &= line_vector_test(0, 0, 1, 0, "Value in middle shifts to left edge after shift", 1, 0, 0, 0); e &= line_vector_test(1, 2, 4, 8, "Distinct values don't combine", 1, 2, 4, 8); e &= line_vector_test(1, 1, 1, 1, "Combinations don't cascade", 2, 2, 0, 0); e &= line_vector_test(0, 0, 1, 1, null, 2, 0, 0, 0); e &= line_vector_test(4, 0, 1, 1, null, 4, 2, 0, 0); e &= line_vector_test(2, 0, 1, 1, null, 2, 2, 0, 0); assertTrue(e); }
0918f7e2-3f60-4dff-89d8-3419d96e77c1
public void test_rotate_clockWise_90degree(){ Game2048Core processer = new Game2048Core(); int[][] in = null; int[][] out = null; int[][] expected = new int[][] { { 2, 0, 2, 2 }, { 0, 0, 0, 0 }, { 0, 2, 0, 0 }, { 0, 2, 0, 2 } }; in = new int[][] { { 2, 0, 0, 2 }, { 2, 0, 0, 0 }, { 0, 0, 2, 2 }, { 2, 0, 0, 0 } }; out=processer.rotate_clockWise_90degree(in); if (GameUtil.compareExpectToActualBoard(expected, out)) { GameUtil.printBoard(in, "after rotate board clockwise 90 degree became", out, expected, GameUtil.PASSED); } else { GameUtil.printBoard(in, "after rotate board clockwise 90 degree became", out, expected, GameUtil.FAILED); fail(); } }
0f240cfd-50f6-4a6b-ab56-3af047004d09
public void test_rotate_clockWise_180degree(){ Game2048Core processer = new Game2048Core(); int[][] in = null; int[][] out = null; in = new int[][] { { 2, 0, 0, 2 }, { 2, 0, 0, 0 }, { 0, 0, 2, 2 }, { 2, 0, 0, 0 } }; int[][] expected = new int[][] { { 0, 0, 0, 2 }, { 2, 2, 0, 0 }, { 0, 0, 0, 2 }, { 2, 0, 0, 2 } }; out=processer.rotate_clockWise_180degree(in); if (GameUtil.compareExpectToActualBoard(expected, out)) { GameUtil.printBoard(in, "after rotate board clockwise 180 degree became", out, expected, GameUtil.PASSED); } else { GameUtil.printBoard(in, "after rotate board clockwise 180 degree became", out, expected, GameUtil.FAILED); fail(); } }
9e80ab59-f6f1-4591-ae9c-c7716113201f
public void test_rotate_clockWise_270degree(){ Game2048Core processer = new Game2048Core(); int[][] in = null; int[][] out = null; in = new int[][] { { 2, 0, 0, 2 }, { 2, 0, 0, 0 }, { 0, 0, 2, 2 }, { 2, 0, 0, 0 } }; int[][] expected = new int[][] { { 2, 0, 2, 0 }, { 0, 0, 2, 0 }, { 0, 0, 0, 0 }, { 2, 2, 0, 2 } }; out=processer.rotate_clockWise_270degree(in); if (GameUtil.compareExpectToActualBoard(expected, out)) { GameUtil.printBoard(in, "after rotate board clockwise 270 degree became", out, expected, GameUtil.PASSED); } else { GameUtil.printBoard(in, "after rotate board clockwise 270 degree became", out, expected, GameUtil.FAILED); fail(); } }
YAML Metadata Error: "language[0]" with value "java" is not valid. It must be an ISO 639-1, 639-2 or 639-3 code (two/three letters), or a special value like "code", "multilingual". If you want to use BCP-47 identifiers, you can specify them in language_bcp47.
YAML Metadata Error: "pretty_name" must be a string
README.md exists but content is empty.
Downloads last month
79

Models trained or fine-tuned on anjandash/java-8m-methods-v2