-
Notifications
You must be signed in to change notification settings - Fork 0
First tests and first bug found and fixed. #2
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package org.example.services; | ||
|
|
||
| import org.example.models.*; | ||
|
|
||
| public interface IServices { | ||
| boolean canBuyWeapon(WeaponModel weapon, int playerScore); | ||
|
|
||
| boolean isPerfectNumber(int artifactCode); | ||
|
|
||
| boolean isPrime(int artifact); | ||
|
|
||
| boolean isTrap(int artifact); | ||
|
|
||
| default boolean isSumDivBy3(int artifact) { | ||
| int sum = 0; | ||
| int num = artifact; | ||
|
|
||
| while (num != 0) { | ||
| sum += num % 10; | ||
| num /= 10; | ||
| } | ||
|
|
||
| return sum % 3 == 0; | ||
| } | ||
|
|
||
| boolean myWinProbability(PlayerStatus opponent, int health, int score); | ||
|
|
||
| double getDistance(PlayerStatus opponent, double posX, double posY); | ||
|
|
||
| boolean winDuel(PlayerStatus opponent, double distance, WeaponModel myWeapon); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,21 +2,20 @@ | |
|
|
||
| import org.example.models.*; | ||
|
|
||
| public class Services { | ||
| public class Services implements IServices { | ||
|
|
||
| private Services() { | ||
| public Services() { | ||
| //empty constructor | ||
| } | ||
|
|
||
| public static int updateScoreService(WeaponModel weapon, int playerScore) { | ||
| return playerScore - weapon.getCost(); | ||
| } | ||
|
|
||
| public static boolean canBuyWeapon(WeaponModel weapon, int playerScore) { | ||
| @Override | ||
| public boolean canBuyWeapon(WeaponModel weapon, int playerScore) { | ||
|
|
||
| return playerScore >= weapon.getCost(); | ||
| } | ||
|
|
||
| public static boolean isPerfectNumber(int artifactCode) { | ||
| @Override | ||
| public boolean isPerfectNumber(int artifactCode) { | ||
| long sum = 0; | ||
| boolean isPerfect = false; | ||
|
|
||
|
|
@@ -25,59 +24,51 @@ public static boolean isPerfectNumber(int artifactCode) { | |
| sum += i; | ||
| } | ||
| } | ||
| if (sum == artifactCode) { | ||
|
|
||
| if (artifactCode == 0) { | ||
| return isPerfect; | ||
| } else if (sum == artifactCode) { | ||
| isPerfect = true; | ||
| } | ||
|
razvanexu marked this conversation as resolved.
Outdated
|
||
| return isPerfect; | ||
| } | ||
|
|
||
| public static boolean isPrime(int artifact) { | ||
| @Override | ||
| public boolean isPrime(int artifact) { | ||
| if (artifact <= 1) { | ||
| return false; | ||
| } | ||
|
|
||
| for (int i = 2; i < Math.sqrt(artifact); i++) { | ||
| for (int i = 2; i < artifact; i++) { | ||
| if (artifact % i == 0) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| public static boolean isTrap(int artifact) { | ||
| return isSumDivBy3(artifact) && isEven(artifact); | ||
| } | ||
|
|
||
| private static boolean isSumDivBy3(int artifact) { | ||
| int sum = 0; | ||
| int num = artifact; | ||
|
|
||
| while (num != 0) { | ||
| sum += num % 10; | ||
| num /= 10; | ||
| } | ||
|
|
||
| return sum % 3 == 0; | ||
| } | ||
|
|
||
| private static boolean isEven(int artifact) { | ||
| return artifact % 2 == 0; | ||
| @Override | ||
| public boolean isTrap(int artifact) { | ||
| return isSumDivBy3(artifact) && artifact % 2 == 0; | ||
| } | ||
|
|
||
| public static boolean winProbability(PlayerStatus opponent, int health, int score) { | ||
| @Override | ||
| public boolean myWinProbability(PlayerStatus opponent, int health, int score) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactor this to use PlayerStatus opponent1, PlayerStatus opponent2 as parameters instead, to be more clear.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. solved in 535b2dd |
||
| var opponentWinProb = (3 * opponent.getHealth() + opponent.getScore() / 1000) / 4; | ||
| var myWinProb = (3 * health + score / 1000) / 4; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create another method that calculates win prob. taking a PlayerStatus player as parameter and use it here instead.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. solved |
||
|
|
||
| return myWinProb > opponentWinProb; | ||
| return myWinProb >= opponentWinProb; | ||
| } | ||
|
|
||
| public static double getDistance(PlayerStatus opponent, double posX, double posY) { | ||
| @Override | ||
| public double getDistance(PlayerStatus opponent, double posX, double posY) { | ||
|
razvanexu marked this conversation as resolved.
Outdated
|
||
| double ac = Math.abs(opponent.getPositionX() - posX); | ||
| double cb = Math.abs(opponent.getPositionY() - posY); | ||
| return Math.hypot(ac, cb); | ||
| } | ||
|
|
||
| public static boolean winDuel(PlayerStatus opponent, double distance, WeaponModel myWeapon) { | ||
| @Override | ||
| public boolean winDuel(PlayerStatus opponent, double distance, WeaponModel myWeapon) { | ||
|
razvanexu marked this conversation as resolved.
Outdated
|
||
| opponent.getWeaponInHand().setCombatValue(distance); | ||
| myWeapon.setCombatValue(distance); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor this to use as parameters (this, opponent) instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
solved