Skip to content

Commit

Permalink
UI valmis ja kattavat jUnit testit luotu
Browse files Browse the repository at this point in the history
  • Loading branch information
mAAstro7 committed Mar 26, 2015
1 parent 675b458 commit 2eb500f
Show file tree
Hide file tree
Showing 65 changed files with 7,398 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/Tiralabra/nbproject/private/
/Tiralabra/build/
/Tiralabra/build/
/Tiralabra/dist/
5 changes: 3 additions & 2 deletions Tiralabra/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
${build.classes.dir}:\
${libs.junit_4.classpath}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
Expand All @@ -53,7 +54,7 @@ javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
main.class=UserInterface.Main
main.class=Main.Main
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
Expand Down
8 changes: 5 additions & 3 deletions Tiralabra/src/ArtificialIntelligence/AI.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,22 @@
*/

public class AI {
private char[] siirrot;
private char[] moves;


/**
* Luo uuden AI:n ja littaa siirrot k,p ja s char taulukkoon
* tätä ei vielä käytetä
*/
public AI(){
this.siirrot = new char[]{'k', 'p', 's'};
this.moves = new char[]{'k', 'p', 's'};
}

/**
* Hakee tekoälyn seuraavan siirron
* Toimii vielä tällä hetkellä randomina
*/
public char getSiirto() {
public char getMove() {
Random random = new Random();
int luku = random.nextInt(100);
int kivi = 33;
Expand Down
49 changes: 49 additions & 0 deletions Tiralabra/src/GameMove/Inspector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package GameMove;

/**
* Luokka voittaja tarkistukseen
* @author Jomppa
*/
public class Inspector {

public Inspector() {

}

/**
* Tarkistaa kömpelösti (atm) kumpi siirroista voittaa.
* @param p1 player1 siirto
* @param p2 player2 siirto
*/
public String checkWhoWins(String p1, String p2) {
if (p1.contains(p2)) {
return "t";
} else if (p1.equals("k")) {
if (p2.equals("s")) {
return "p1";
} else {
return "p2";
}
}
else if (p1.equals("s")) {
if (p2.equals("p")) {
return "p1";
} else {
return "p2";
}
} else if (p1.equals("p")) {
if (p2.equals("k")) {
return "p1";
} else {
return "p2";
}
} else {
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

package UserInterface;
package Main;

import UserInterface.UI;

/**
*
Expand All @@ -8,7 +10,7 @@
public class Main {



public static void main(String[] args) {
UI kayttoliittyma = new UI();
kayttoliittyma.run();
Expand Down
9 changes: 7 additions & 2 deletions Tiralabra/src/Player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ public int getPoints() {
return points;
}

public void setPoints(int pisteet) {
this.points = pisteet;
public void setPoints(int points) {
this.points = points;
}

@Override
public String toString() {
return this.name + " scores: " + this.points;
}

}
43 changes: 42 additions & 1 deletion Tiralabra/src/UserInterface/UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import Player.Player;
import ArtificialIntelligence.AI;
import GameMove.Inspector;
import java.util.Scanner;

/**
Expand All @@ -14,14 +15,54 @@ public class UI {
private AI botti = new AI();
private Player player1 = new Player();
private Player player2 = new Player();
private Inspector inspa = new Inspector();

public UI () {


}

/**
* Suorittaa ohjelman
*/
public void run() {
Scanner lukija = new Scanner(System.in);
createPlayers();
int i =0;
//Tässä vaiheessa voi pelata seitsemän siirron testipelejä
while (i<7) {
System.out.println(getScores());
System.out.println("Choose your move: k,p,s");
String siirto1 = lukija.next();
while (!siirto1.equals("k") && !siirto1.equals("s") && !siirto1.equals("p")) {
System.out.println("Choose better, remember: k,p,s");
siirto1 = lukija.next();
}

String siirto2 = botti.getMove()+"";
String voittaja = inspa.checkWhoWins(siirto1, siirto2);
System.out.println(player1.getName()+" chooses " + siirto1 + " and " + player1.getName()+" chooses "+ siirto2);

if (voittaja.contains("p1")) {
System.out.println("Winner is " + player1.getName());
player1.addPoint();
} else if (voittaja.contains("p2")) {
System.out.println("Winner is " + player2.getName());
player2.addPoint();
}
i++;

}

System.out.println(getScores());
}

/**
* Palauttaa pelaajien toString joka kertoo nimen ja pistemäärän
*/
public String getScores() {

return player1.toString() +" "+ player2.toString();
}

/**
Expand All @@ -42,7 +83,7 @@ public void createPlayers() {
public void makeMove() {
Scanner lukija = new Scanner(System.in);
String siirto = lukija.nextLine();
String siirto2 = botti.getSiirto()+"";
String siirto2 = botti.getMove()+"";
}


Expand Down
38 changes: 38 additions & 0 deletions Tiralabra/test/ArtificialIntelligence/AITest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ArtificialIntelligence;

import org.junit.Assert;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.junit.Test;

/**
*
* @author Jomppa
*/
public class AITest {

private AI ai = new AI();

public AITest() {

}
/**
* Testataan valitseeko tekoäly siirroksi k, p tai s
*/
@Test
public void canAIMakeMoveK() {
String move = ai.getMove()+"";
if (move.equals("k") || move.equals("s") || move.equals("p")) {

assertFalse("".contains(move));
} else {
assertFalse("I didnt make k, p or s :(", move.contains(""));
}

}
}
47 changes: 47 additions & 0 deletions Tiralabra/test/GameMove/InspectorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package GameMove;

import Player.Player;
import static org.junit.Assert.assertEquals;
import org.junit.Test;

/**
*
* @author Jomppa
*/
public class InspectorTest {

private Inspector inspa = new Inspector();

public InspectorTest() {

}

/**
* Testataan toimiiko p1 voiton selvitys
*/
@Test
public void doInspGetWinner() {
assertEquals("p1", inspa.checkWhoWins("k", "s"));
}

/**
* Testataan toimiiko p1 tasurin selvitys
*/
@Test
public void doInspGetTie() {
assertEquals("t", inspa.checkWhoWins("s", "s"));
}

/**
* Testataan toimiiko p1 häviön selvitys
*/
@Test
public void doInspGetLoser() {
assertEquals("p2", inspa.checkWhoWins("s", "k"));
}
}
38 changes: 38 additions & 0 deletions Tiralabra/test/Player/PlayerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Player;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

/**
*
* @author Jomppa
*/
public class PlayerTest {
private Player p1 = new Player();

public PlayerTest () {
p1.setName("Matti");

}
/**
* Testataan toimiiko getName
*/
@Test
public void isNameRight() {
assertEquals("Matti" , p1.getName());
}

/**
* Testataan toimiiko pisteiden kasvatus
*/
@Test
public void pointsAreGrowing() {
p1.addPoint();
assertEquals(1 , p1.getPoints());
}
}
Binary file added doc/Viikkoraportti 2.pdf
Binary file not shown.
Binary file added doc/Viikkoraportti 3.pdf
Binary file not shown.
Binary file added doc/dokumentaatio.docx
Binary file not shown.
Loading

0 comments on commit 2eb500f

Please sign in to comment.