id
stringlengths
36
36
text
stringlengths
1
1.25M
88ebf17f-4cd0-43af-9736-8108c9d1adc8
public int getRow() { return y; }
cfaa9e4f-2b07-4151-8943-9b195707e67c
public int getCol() { return x; }
594c1bb9-06ed-4ed4-a918-de7eda684e21
public int getAlpha() { /* get the value at the location from the picture as a 32 bit int * with alpha, red, green, blue each taking 8 bits from left to right */ int value = picture.getBasicPixel(x,y); // get the alpha value (starts at 25 so shift right 24) // then and it with all 1's fo...
3d7efd78-7121-4aa5-b9a8-ad575050c32e
public int getRed() { /* get the value at the location from the picture as a 32 bit int * with alpha, red, green, blue each taking 8 bits from left to right */ int value = picture.getBasicPixel(x,y); // get the red value (starts at 17 so shift right 16) // then AND it with all 1's for t...
391115ee-6077-4b25-8237-bd4b0a656d7f
public static int getRed(int value) { int red = (value >> 16) & 0xff; return red; }
f23ad506-1686-4295-b952-79fe21d50e40
public int getGreen() { /* get the value at the location from the picture as a 32 bit int * with alpha, red, green, blue each taking 8 bits from left to right */ int value = picture.getBasicPixel(x,y); // get the green value (starts at 9 so shift right 8) int green = (value >> 8) & 0xf...
79a22af1-bdea-429c-88a9-59d9ab89ee59
public static int getGreen(int value) { int green = (value >> 8) & 0xff; return green; }
b4752ea7-063f-4d16-a215-2a7764fbd76f
public int getBlue() { /* get the value at the location from the picture as a 32 bit int * with alpha, red, green, blue each taking 8 bits from left to right */ int value = picture.getBasicPixel(x,y); // get the blue value (starts at 0 so no shift required) int blue = value & 0xff; ...
3aaafcc1-4f8e-4476-a2e1-e03a2f753eae
public static int getBlue(int value) { int blue = value & 0xff; return blue; }
af3c4169-0d20-4dc0-90fa-73bf3f4d7e78
public Color getColor() { /* get the value at the location from the picture as a 32 bit int * with alpha, red, green, blue each taking 8 bits from left to right */ int value = picture.getBasicPixel(x,y); // get the red value (starts at 17 so shift right 16) // then AND it with all 1's fo...
8e194d83-b5da-4bf0-bce0-e0afe42d7b52
public void setColor(Color newColor) { // set the red, green, and blue values int red = newColor.getRed(); int green = newColor.getGreen(); int blue = newColor.getBlue(); // update the associated picture updatePicture(this.getAlpha(),red,green,blue); }
b5c719de-1040-4663-b76b-cbd60f3c40fb
public void updatePicture(int alpha, int red, int green, int blue) { // create a 32 bit int with alpha, red, green blue from left to right int value = (alpha << 24) + (red << 16) + (green << 8) + blue; // update the picture with the int value picture.setBasicPixel(x,y,value); }
3652ffca-e9a9-4042-9e4f-c14486fb1337
private static int correctValue(int value) { if (value < 0) value = 0; if (value > 255) value = 255; return value; }
b31d6046-4074-4ff8-b1ad-f673b41b1973
public void setRed(int value) { // set the red value to the corrected value int red = correctValue(value); // update the pixel value in the picture updatePicture(getAlpha(), red, getGreen(), getBlue()); }
d621e836-684c-4c39-a121-7f25ecf2fd9c
public void setGreen(int value) { // set the green value to the corrected value int green = correctValue(value); // update the pixel value in the picture updatePicture(getAlpha(), getRed(), green, getBlue()); }
4b67f780-f2d2-4f37-ba62-a484a5e10682
public void setBlue(int value) { // set the blue value to the corrected value int blue = correctValue(value); // update the pixel value in the picture updatePicture(getAlpha(), getRed(), getGreen(), blue); }
5668b33c-0021-4934-a647-bf33a6443f0a
public void setAlpha(int value) { // make sure that the alpha is from 0 to 255 int alpha = correctValue(value); // update the associated picture updatePicture(alpha, getRed(), getGreen(), getBlue()); }
a357e8bb-bb79-4f94-b30f-528d3290583d
public double colorDistance(Color testColor) { double redDistance = this.getRed() - testColor.getRed(); double greenDistance = this.getGreen() - testColor.getGreen(); double blueDistance = this.getBlue() - testColor.getBlue(); double distance = Math.sqrt(redDistance * redDistance + ...
aac8b689-da51-42ad-ae73-30f0e09f2127
public static double colorDistance(Color color1,Color color2) { double redDistance = color1.getRed() - color2.getRed(); double greenDistance = color1.getGreen() - color2.getGreen(); double blueDistance = color1.getBlue() - color2.getBlue(); double distance = Math.sqrt(redDistance * redDistance + ...
243fe1cd-f311-4e33-bd36-80d174c5d1d7
public double getAverage() { double average = (getRed() + getGreen() + getBlue()) / 3.0; return average; }
bd82034a-5d1a-4a65-8446-fd284cda380a
public String toString() { return "Pixel row=" + getRow() + " col=" + getCol() + " red=" + getRed() + " green=" + getGreen() + " blue=" + getBlue(); }
3b5a2749-941d-4a44-9fde-d8cc4f656f9a
public Modulo(double modif, double modifAvv) { this.modif = modif; this.modifAvv = modifAvv; }
b5626116-0f3f-4781-ae0c-9014e7b9130f
@Override public String toString() { return "Mod:"+modif+",modAvv:"+modifAvv; }
760c59f6-32ee-41da-b9f9-5d9dcfd63474
public static void build(String[] competizioni) { SelezioneCompetizione inst = new SelezioneCompetizione(competizioni); inst.setVisible(true); }
9d11e07b-c814-48ed-a619-118edda22e7e
public SelezioneCompetizione(String[] competizioni) { super(); initGUI(competizioni); }
c16c8bcc-078b-441c-af47-e2eaff981af8
private void initGUI(String[] competizioni) { try { this.setTitle("Selezione Competizione"); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); { jPanel1 = new JPanel(); getContentPane().add(jPanel1, BorderLayout.CENTER); jPanel1.setLayout(null); jPanel1.setBackground(new java.awt.Co...
5146e059-ee1c-47ab-99e3-20de9d1b0dfa
public void actionPerformed(ActionEvent arg0) { if (arg0.getSource().equals(ok)){ CalendariIncrociati.calc(listaCompetizioni.getItemAt(listaCompetizioni.getSelectedIndex()).toString(),2); this.dispose(); } if (arg0.getSource().equals(annulla)){ this.dispose(); System.exit(1); } }
31e53562-6797-472a-9c3f-53e6ec9a881e
public Regole (Statement stmt, String compSel) throws SQLException{ ResultSet rs = stmt.executeQuery("SELECT puntipervittoria, fattorecampo, regolaportiere, regoladifesa, regolacentmedia, " + "regolacentdiffe, regoladiff4, regoladiff10, regolamin60, usaspeciale1, " + "usaspeciale2, usaspeciale3, regolaattacco...
6d3bdaa3-f958-4446-8d17-6fd1c22bbea8
public static void build() { SelezioneLega inst = new SelezioneLega(); inst.setVisible(true); }
b0520eb5-bad1-4b8c-8d2f-4ce892d3c08e
public SelezioneLega() { super(); initGUI(); }
a2f6a99a-f7dd-4165-87da-0e083fa6d22a
private void initGUI() { try { this.setTitle("Selezione Lega"); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); { jPanel1 = new JPanel(); getContentPane().add(jPanel1, BorderLayout.CENTER); jPanel1.setLayout(null); jPanel1.setBackground(new java.awt.Color(220,228,231)); { ...
c0485f57-bef2-4778-be3c-32b0f51f2e40
public void actionPerformed(ActionEvent arg0) { if (arg0.getSource().equals(sfoglia)){ JFileChooser jFileChooser1 = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Database FCM", "fcm"); jFileChooser1.setFileFilter(filter); int returnVal = jFileChooser1.showOpenDialog(thi...
8d7e08d7-9ab4-4147-8181-b5759c4f3f2c
public static void build(String[] competizioni) { SelezioneGirone inst = new SelezioneGirone(competizioni); inst.setVisible(true); }
497fc5ba-dcbe-436c-81d7-e64ccd12580d
public SelezioneGirone(String[] competizioni) { super(); initGUI(competizioni); }
7111db21-7470-40ca-baf8-02ca45a68944
private void initGUI(String[] gironi) { try { this.setTitle("Selezione Girone"); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); { jPanel1 = new JPanel(); getContentPane().add(jPanel1, BorderLayout.CENTER); jPanel1.setLayout(null); jPanel1.setBackground(new java.awt.Color(220,228,...
7625e93a-ec0a-4ca2-aa27-7f48a37da3ac
public void actionPerformed(ActionEvent arg0) { if (arg0.getSource().equals(ok)){ CalendariIncrociati.calc(listaGironi.getItemAt(listaGironi.getSelectedIndex()).toString(),3); this.dispose(); } if (arg0.getSource().equals(annulla)){ this.dispose(); System.exit(1); } }
653ca986-94b6-4f08-8b69-207d9503763a
public static java.sql.Connection getAccessDBConnection(String filename) throws SQLException { filename = filename.replace('\\', '/').trim(); String databaseURL = accessDBURLPrefix + filename + accessDBURLSuffix; CalendariIncrociati.logger.info("Stringa di connessione: "+databaseURL); return DriverManager.getCo...
3096a43a-fe1a-4382-8173-162f653b05a5
@Before public void setUp() throws Exception { player = new HumanPlayer("me", 500); }
ff7261bb-d788-4859-9f03-e9fcd97c49ea
@Test public void testGetChipCount() { assertTrue(player.getChipCount() == 500); }
3db9e516-dc34-403c-8184-7fc28ccbc843
@Test public void testWinBet() { player.betChips(100); player.winBet(); assertTrue(player.getChipCount() == 600); }
28f3d57b-7b38-48eb-b0a6-2c820b616a78
@Test public void testLooseBet() { player.betChips(30); player.looseBet(); assertTrue(player.getChipCount() == 470); }
7c52c9c0-07bd-4540-a8a5-b73f9fb0d0bb
@Before public void setUp() { number = new Card(3); face = new Card(11); ace = new Card(1); }
d160a4b7-36f0-4f15-8858-af8e8a73487e
@Test public void testGetCardValue() { boolean acesLow = true; assertTrue(number.getCardValue(acesLow) == 3); assertTrue(face.getCardValue(acesLow) == 10); assertTrue(ace.getCardValue(acesLow) == 1); acesLow = false; assertTrue(number.getCardValue(acesLow) == 3); assertTrue(face.getCardValue(acesLow) =...
75afafb0-1813-436e-a05b-b5cc6b05074a
@Test public void testToString() { assertTrue(number.toString().equals("3")); assertTrue(face.toString().equals("J")); assertTrue(ace.toString().equals("A")); }
f3ab29ef-344e-4341-bddb-b2acc0af6df5
@Before public void setUp() throws Exception { game = new Game(); }
ca0f3d4e-b835-4eff-9599-0d765aead69a
@Test public void testGetDeck() { assertTrue(game.getDeck().numCardsRemaining() == 52); }
e5ece83a-1d04-495a-91a2-9c410656a506
@Before public void setUp() throws Exception { hand = new Hand(); }
660d2e20-fe5f-458f-9cae-857c74bc621c
@Test public void testAddCard() { hand.addCard(new Card(3)); hand.addCard(new Card(1)); hand.addCard(new Card(12)); assertTrue(hand.getTotalHandValue() == 14); }
35cb2880-ae13-4715-b337-9cd5df7b18e8
@Test public void testClear() { hand.addCard(new Card(12)); hand.clear(); assertTrue(hand.getTotalHandValue() == 0); }
b58c8bcf-43f5-421a-b332-62b50b424ed2
@Test public void testToString() { hand.addCard(new Card(3)); hand.addCard(new Card(1)); hand.addCard(new Card(12)); assertTrue(hand.toString().equals("3 A Q ")); }
afdeee6c-8924-4672-ad72-a4237aa697f6
@Test public void testToStringShowingTopCardOnly() { hand.addCard(new Card(3)); hand.addCard(new Card(1)); hand.addCard(new Card(12)); assertTrue(hand.toStringShowingTopCardOnly().equals("3 X X ")); }
505ea28c-129f-43ca-9d1a-5b89cc85e443
@Before public void setUp() throws Exception { hit = new ComputerDealer("hit"); hit.dealCard(new Card(7)); hit.dealCard(new Card(9)); stay = new ComputerDealer("stay"); stay.dealCard(new Card(10)); stay.dealCard(new Card(11)); }
97a2df69-06e5-4552-9ee2-96f930910e93
@Test public void testTakeAction() { assertTrue(hit.getName().equals("hit")); assertTrue(hit.getHand().getTotalHandValue() == 16); assertTrue(hit.takeAction(null) == Action.Hit); assertTrue(stay.takeAction(null) == Action.Stay); }
04f9f8d0-7651-40a8-b5a4-4bca1bbcf8e4
@Before public void setUp() throws Exception { player = new HumanPlayer("me", 500); }
b49b4b98-7e1f-4cb4-ac85-1c6f39d2b8c7
@Test public void testNewHand() { player.getHand().addCard(new Card(13)); assertTrue(player.getHand().getTotalHandValue() == 10); player.newHand(); assertTrue(player.getHand().getTotalHandValue() == 0); }
2788baf2-99b1-4b4c-a62a-9a1be5e79821
@Test public void testDealCard() { player.dealCard(new Card(13)); assertTrue(player.getHand().getTotalHandValue() == 10); }
8d37d98c-7faf-4369-a7b7-65462fc0d966
@Test public void testGetName() { assertTrue(player.getName().equals("me")); }
3293863d-5bc4-49b0-9605-3a499b4099e2
@Test public void testToString() { assertTrue(player.toString().equals("me: Current Hand: ")); player.dealCard(new Card(3)); player.dealCard(new Card(1)); assertTrue(player.toString().equals("me: Current Hand: 3 A ")); }
da7fe09a-83e9-463a-abee-58c88d5583ba
@Test public void testToStringShowingTopCardOnly() { assertTrue(player.toStringShowingTopCardOnly().equals( "me: Current Hand: ")); player.dealCard(new Card(3)); player.dealCard(new Card(1)); assertTrue(player.toStringShowingTopCardOnly().equals( "me: Current Hand: 3 X ")); }
556a3c66-f834-4344-9983-00c0e1d7ab20
@Before public void setUp() throws Exception { deck = new Deck(); }
7e92a0b3-820f-4e78-afd1-47999037cfa4
@Test public void testRemoveCard() { assertTrue(deck.numCardsRemaining() == 52); int threeCount = 0; int jackCount = 0; int aceCount = 0; for (int i = 0; i < 52; i++) { Card card = deck.removeCard(); if (card.toString().equals("3")) threeCount++; if (card.toString().equals("J")) jackCoun...
255e3fcc-b26d-419f-8e12-07a4e9fccbeb
public HumanPlayer(String name, int startingChips) { super(name); this.chips = startingChips; this.currentBet = INVALID_BET_FLAG; // no current bet }
ae9e38fe-43df-4b33-aae1-d5b1f8b8df87
@Override public Action takeAction(UI ui) { return ui.getUserActionChoice(); }
64469129-2f78-4790-9dd6-f8bc26d9fbd8
public int getChipCount() { return chips; }
55c2f9a8-5afb-4b24-be63-40c7a0831e04
public void betChips(int chips) { this.currentBet = chips; }
e5345f38-7c47-483f-a2e1-f6558fbff6fc
public void winBet() { if (this.currentBet == INVALID_BET_FLAG) log.error("Player.winBet() called without bet placed."); else { log.info("Bet won: " + this.currentBet); winChips(this.currentBet); this.currentBet = INVALID_BET_FLAG; // reset currentBet } }
eed12a41-3d9d-4a2f-99c7-c00503b57d0e
public void looseBet() { if (this.currentBet == INVALID_BET_FLAG) log.error("Player.looseBet() called without bet placed."); else { log.info("Bet lost: " + this.currentBet); loseChips(this.currentBet); this.currentBet = INVALID_BET_FLAG; // reset currentBet } }
0c2f0aa0-db1f-46ea-9dc8-a44c904a5dce
private void winChips(int chips) { this.chips += chips; }
df8f24e4-7e51-4878-b6ba-caef277a8633
private void loseChips(int chips) { this.chips -= chips; }
29f56ecb-b0d9-4379-b7fe-b284f40f1a4d
public Player(String name) { this.name = name; hand = new Hand(); }
5692e6f6-0e74-4866-be96-1302efa422dd
public void newHand() { log.debug("New hand"); hand.clear(); }
ac685977-2d3f-4741-9c10-26dd5b2a4a34
public void dealCard(Card card) { log.debug("Adding card to hand: " + card); hand.addCard(card); }
4666be92-5651-4dc1-901f-21f0def1896f
public String getName() { return name; }
5e9f85ba-a9b1-4fb2-a718-6818e74aa235
public Hand getHand() { return hand; }
a45eb57f-eed5-40fb-aaee-3cfdeeff62d4
public String toString() { return name + ": Current Hand: " + hand; }
d5b14a07-62b2-4f70-9948-ffb7c73eed91
public String toStringShowingTopCardOnly() { return name + ": Current Hand: " + hand.toStringShowingTopCardOnly(); }
3b4cb8bc-a309-4fd0-9eb7-52873c0cbd37
public abstract Action takeAction(UI ui);
82710181-f610-4f64-81b3-b448b8d07554
public Deck() { this(STANDARD_DECK_SIZE); }
09c6319c-fb4f-4825-894b-6ee8cb755483
public Deck(int deckSize) { this.deckSize = deckSize; cards = new Stack<Card>(); newDeck(); }
c64782fd-bad7-4a1e-81bf-76bda5bab4e9
public void newDeck() { log.info("Generating new deck"); cards.clear(); // This loop supports blackjack games where more than one deck is used. // Use of more than one deck increases the house advantage. // Repeat for each multiple of STANDARD_DECK_SIZE for (int d = 0; d < (deckSize / STANDARD_DECK_SIZE...
0687583a-78b7-4675-af15-81f479d2ab71
public Card removeCard() { return cards.pop(); }
bf491d5f-ba55-4bc3-ad99-dcb857bd4f86
public int numCardsRemaining() { return cards.size(); }
b9794bd9-38d0-4f0d-883b-aee3f935d85a
public ComputerDealer(String name) { super(name); }
61a00611-c678-4625-bb66-003396320a76
@Override public Action takeAction(UI ui) { int handValue = hand.getTotalHandValue(); log.info("ComputerDealer takes action on hand value: " + handValue); if (handValue > Hand.MAX_HAND_VALUE) return Action.Bust; if (handValue >= STAY_VALUE) return Action.Stay; else return Action.Hit; }
d8f6f411-4cc8-498e-8561-7b9c66b965c0
public GameQuitException() { }
869c77d6-7914-4dd0-8d92-5819f72951cc
public GameQuitException(String message) { super(message); }
82bba9b6-d075-47bb-be8a-5124a47779a6
public GameQuitException(Throwable cause) { super(cause); }
9dddf40b-f6ce-414e-966f-6d18cac5a811
public GameQuitException(String message, Throwable cause) { super(message, cause); }
d683cd3c-de2e-446b-bad7-81b64d512dbb
public Game() { this(STARTING_CHIPS); }
bdb03b07-4113-4727-838e-eed6b7030584
public Game(int startingChips) { ui = new ConsoleUI(); deck = new Deck(); dealer = new ComputerDealer("Dealer"); player = new HumanPlayer("Player", startingChips); }
0fbe8214-2f0c-4f3b-8a16-5195d7ae0969
public void play() { try { // Note: Using the term "round" instead of "hand" to avoid confusion // with the term "hand" meaning the cards currently held by a user int roundNumber = 0; // Loop over rounds of play until player is out of chips or quits while (player.getChipCount() > 0) { roundNu...
0807c738-5a15-48ad-b17b-8764f672b81d
private void dealCards() { log.info("Dealing cards"); checkForLowDeck(); player.newHand(); dealer.newHand(); // First card player.dealCard(deck.removeCard()); dealer.dealCard(deck.removeCard()); // Second card player.dealCard(deck.removeCard()); dealer.dealCard(deck.removeCard()); }
7f2d1c5e-c11c-4bf8-990e-d1149f4229b7
private void checkForLowDeck() { if (deck.numCardsRemaining() < Deck.LOW_DECK_SIZE) { log.info("Deck low - bringing in new deck"); deck.newDeck(); } }
9837b245-a309-42a3-8ec4-763950074356
private int handleActions(Player currentPlayer) { // loop until Stay or Bust boolean actionsPending = true; while (actionsPending) { Action action = currentPlayer.takeAction(ui); log.info("Handling " + action + " for " + currentPlayer.getName()); switch (action) { case Hit: currentPlayer.d...
5d7595d1-7155-40c8-8008-5fcf6c40397e
private void endRound(int playerOutcome, int dealerOutcome) { switch (Game.assessHandWinner(playerOutcome, dealerOutcome)) { case PlayerWins: log.info("Player wins round"); ui.playerWinsRound(); player.winBet(); break; case DealerWins: log.info("Dealer wins round"); ui.dealerWinsRound(); p...
b76a31c3-6fe9-4024-a35f-44eb727c206b
private static Hand.Result assessHandWinner(int playerOutcome, int dealerOutcome) { if (playerOutcome > Hand.MAX_HAND_VALUE && dealerOutcome > Hand.MAX_HAND_VALUE) return Hand.Result.Push; if (playerOutcome > Hand.MAX_HAND_VALUE) return Hand.Result.DealerWins; if (dealerOutcome > Hand.MAX_HAND_VALUE...
faa30a09-235c-43dc-a91a-6a03498106be
private void quitGame() { ui.quitMessage(); }
8b7c7c86-5d43-4b87-bb3b-87a2db538c34
private UI getUI() { return ui; }
9fe5420d-e28a-41c7-8e9b-249c0a4ece85
public Deck getDeck() { return deck; }
9fe77ac7-abe0-4d5e-b383-52f459b0a6a7
public static void main(String[] args) { Game currentGame = new Game(); UI ui = currentGame.getUI(); ui.introMsg(); currentGame.play(); ui.exitMsg(); }