This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <LinearLayout | |
| xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:app="http://schemas.android.com/apk/res-auto" | |
| android:layout_width="match_parent" | |
| android:layout_height="wrap_content"> | |
| <ImageView | |
| android:id="@+id/imageView" | |
| android:layout_width="wrap_content" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public double evaluate() { | |
| return isEndOfGameState() // se of jogo acabou (alguém ganhou ou o tabuleiro está cheio) | |
| ? utility() // então devolver pontuação 0, +infinito ou -infinito (consoante seja empate, o agente a ganhar ou o oponente a ganhar) | |
| : getWinningPossibilities(agentPiece) - getWinningPossibilities(opponentPiece); // senão devolver uma pontuação de acordo com a heurística definida | |
| } | |
| // devolve o número de possibilidades que determinado jogador tem de ganhar a partir deste estado | |
| private int getWinningPossibilities(char player) { | |
| char other = player == X ? O : X; | |
| int possibilities = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Minimax extends GameAlgorithm { | |
| //MINIMAX-DECISION(state) returns an action | |
| // max = -∞ | |
| // For each a from ACTIONS(state) do | |
| // v = MIN-VALUE(RESULT(state, a), 1) | |
| // If (v > max) max = v; action = a | |
| // returns action | |
| @Override | |
| public Action takeDecision(AgentState currentState) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package agent; | |
| import common.Action; | |
| public class AlphaBeta extends GameAlgorithm { | |
| //ALFABETA-DECISION(state) returns an action | |
| // max = -∞ | |
| // For each a from ACTIONS(state) do | |
| // v = MINVALUE(RESULT(state, a), max, +∞, 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Override | |
| public Solution search(Problem problem) { | |
| statistics.reset(); | |
| stopped = false; | |
| this.heuristic = problem.getHeuristic(); | |
| limit = heuristic.compute(problem.getInitialState()); | |
| Solution solution; | |
| do { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Override | |
| public Solution search(Problem problem) { | |
| statistics.reset(); | |
| stopped = false; | |
| this.heuristic = problem.getHeuristic(); | |
| limit = heuristic.compute(problem.getInitialState()); | |
| Solution solution; | |
| do { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <LinearLayout | |
| xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| android:orientation="vertical" | |
| tools:context="pt.ipleiria.awareness.MainActivity"> | |
| <LinearLayout |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // more info: https://stackoverflow.com/a/12878774 | |
| Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonDeserializer<Date> () { | |
| public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | |
| // example string: "/Date(1513943979489+0000)/" | |
| String s = json.getAsJsonPrimitive().getAsString(); | |
| // A plus sign (+) indicates hours ahead of GMT and a minus sign (-) indicates hours behind GMT | |
| // https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings | |
| // FIX: ignore the sign, and digits after it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <LinearLayout | |
| xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| android:orientation="vertical" | |
| tools:context="pt.ipleiria.contacts.AddActivity"> | |
| <EditText |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <LinearLayout | |
| xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| android:orientation="vertical" | |
| tools:context="pt.ipleiria.contacts.SearchActivity"> | |
| <EditText |