Skip to content

Conversation

@a1shadows
Copy link
Contributor

Issue #9

Game trait created.
added missing isTerminalState function
minimaxsearch added
@a1shadows
Copy link
Contributor Author

@BusyByte Hey, could you please resolve the conflicts and review the pull request. Thanks.

@a1shadows a1shadows changed the title Minimax search function [WIP]Minimax search function Mar 29, 2019
@a1shadows a1shadows changed the title [WIP]Minimax search function [WIP] Minimax search function Mar 29, 2019
Copy link
Collaborator

@BusyByte BusyByte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes needed but looks good overall.
Can you add a test specification (specs2) and/or a scalacheck (property based check) to prove it works?
If there are examples from the book sometimes I'll use those to prove it works.

@BusyByte
Copy link
Collaborator

@a1shadows sorry something wasn't quite right with my resolution of the merge conflicts, hopefully you can fix it up

@BusyByte
Copy link
Collaborator

@a1shadows let me know if you have any questions on the above or need help

case a :: Nil used instead to improve consistency with other cases.
Integrated all requested changes and remedied handful of syntactical and logical errors.
@a1shadows
Copy link
Contributor Author

@BusyByte Have tried addressing all the requested changes. Am working on testing the code. Could you please review the changes?

Copy link
Collaborator

@BusyByte BusyByte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@a1shadows this looks good but still missing a test specification/property based test.

--edit never mind above, I just saw you were working on the testing code still

@a1shadows
Copy link
Contributor Author

@a1shadows this looks good but still missing a test specification/property based test

I'll do the test code. I have my mid-terms till the 28th. Just need a little bit of time. Thanks for your constant guidance.

a1shadows added 2 commits May 1, 2019 17:49
added test problem for minimax
test spec for minimax
@a1shadows
Copy link
Contributor Author

@BusyByte I've written a test for the function, but I'm having some difficulty coming up with more tests. Could you please review the new code and suggest how I should proceed with the tests?

@BusyByte
Copy link
Collaborator

BusyByte commented May 5, 2019

@a1shadows fyi travis has broken, I've merge a fix to master for it now:
#72

you'll need to merge master in order to get travis to run your tests

case class State(stateNumber: Int) extends AnyVal
case class Action(stateNumber: Int) extends AnyVal

object TwoPlyGame extends Game[Player, State, Action] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth explaining what this game is and if it's in the book at all provide documentation (comments around it and how it works).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please give an example of the format in which I'm supposed to give the comment about the function?

"The two-ply game " should {
"should return action to state 1 from state 0" in {
MinimaxDecision
.minMaxDecision[Player, State, Action](TwoPlyGame, Action(-1))(TwoPlyGame.initialState, TwoPlyGame.Players(1))
Copy link
Collaborator

@BusyByte BusyByte May 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than having a special integer value to signify no action why not have action be a sum type

sealed trait Action
case object NoAction extends Action
final case class MoveToState(s : State) extends Action

/**
* @author Aditya Lahiri
*/
case class Player(name: String) extends AnyVal
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there can only be 2 players why not code it that way;

sealed abstract class Player {
def name: String
}

final case class Player1(name: String) extends Player
final case class Player2(name: String) extends Player

1 -> List(Action(4), Action(5), Action(6)),
2 -> List(Action(7), Action(8), Action(9)),
3 -> List(Action(10), Action(11), Action(12)))
val States = Map(0 -> State(0),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this might go away with changes I outlined below to Action.

@BusyByte
Copy link
Collaborator

BusyByte commented May 5, 2019

@a1shadows might be worth going through a full game and verifying each player's actions are what you expect and not just the first one and verify you get NoAction at the end.
I left some suggestions above but this seems pretty good so far.

@BusyByte
Copy link
Collaborator

BusyByte commented May 5, 2019

@a1shadows also since this is adversarial maybe verify who should win and maybe a comment as to why

@a1shadows
Copy link
Contributor Author

I'm getting a ton of errors on the code when I'm running it on the sbt which weren't there earlier. I can't understand them.
They are all of this kind:

aima-scala\core\src\main\scala\aima\core\agent\Actuator.scala:8:16: type parameter Action defined in trait Actuator shadows trait Action defined in package agent. You may want to rename your type parameter, or possibly remove it.

Could you point me to what's going wrong, please?

@a1shadows
Copy link
Contributor Author

Also, would it be possible to set up a gitter channel to discuss the repository? For general queries and the like?

@BusyByte
Copy link
Collaborator

@a1shadows I've created a gitter channel, you should get an invitation, I think the error you are seeing is because of a name collision. Maybe try upper case A in your type parameter or upper case ACTION
for example.
trait Foo[A] or trait Bar[ACTION]

@BusyByte
Copy link
Collaborator

@a1shadows maybe you need to do a sbt clean sbt ";clean;test:compile" after you merge master into your branch.
I don't think there is a trait Action defined in package agent in package agent anymore looking at master.

@BusyByte
Copy link
Collaborator

@a1shadows this still says WIP in the title. Is there anything else you'd like to do before merging this?

@a1shadows
Copy link
Contributor Author

a1shadows commented Jul 1, 2019 via email

@a1shadows
Copy link
Contributor Author

@BusyByte Hey, I was attempting to rewrite the code to give an optimal state for the game at every level as opposed to my earlier code that only gave the next best move, but I just realized that the pseudocode only provides an algorithm for the next best move with the assumption that the "MAX" player is making the move. I am unsure how to proceed from here on. Should I try to write the code for the complete algorithm that can calculate moves for both "MIN" and "MAX" players or should I restrict myself to what the book has provided?

@BusyByte
Copy link
Collaborator

BusyByte commented Jul 20, 2019

@a1shadows Looking at the test for the Java version it looks like it should handle both players.

Looking at the Java implementation it just determines which player's turn it is based on the state. So when you call the search function you give it a state so it should just handle it naturally.

I think it selects the max utility of the minimum utility assuming the next player will pick the min. So it doesn't look like the algorithm needs changed to handle both users.

I think your spec may need to change to handle both users.
It looks like the java spec is implementing aima 3e Fig 5.2

Sorry for the delay in response. Work has been pretty hectic lately.

@BusyByte
Copy link
Collaborator

BusyByte commented Jan 15, 2020

@a1shadows is this good to go? If you are satisfied I can merge it. It still says WIP in the title so I'm inclined to wait.

@a1shadows
Copy link
Contributor Author

a1shadows commented Jan 15, 2020 via email

@a1shadows
Copy link
Contributor Author

Still ironing a few things out. I'll let you know when I'm comfortable with the changes. Is that okay?

@BusyByte
Copy link
Collaborator

@a1shadows yeah, that's fine but please prioritize this as there are some more PRs coming through and I don't want you to have a bunch of merge conflicts to work through since your PR predates them.

@a1shadows
Copy link
Contributor Author

I'm satisfied with my changes. Can you review and merge?

Copy link
Collaborator

@BusyByte BusyByte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some things I'd change but this looks good.


final case class UtilityValue(value: Double) extends AnyVal
final case class UtilityValue(value: Double) extends AnyVal {
def <(that: UtilityValue) = if (this.value < that.value) true else false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really this should be typeclass

def getUtility(state: S): UtilityValue
}

trait Player {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like having traits with no defined behavior.
I'd just as soon keep these in the definition of the given game so they can be sealed and compile time checked to be total matched.

@BusyByte BusyByte merged commit e4e4b06 into aimacode:master Feb 1, 2020
maxValue(g.result(state, minMaxValue(g.getActions(state))))
}

maxMinValue(g.getActions(g.initialState))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@a1shadows I was looking at this when trying to implement alpha beta search and have a question. Why are you passing in the g.initialState rather than state which is passed into the function? this does not seem to match the algorithm.

@a1shadows
Copy link
Contributor Author

a1shadows commented Mar 9, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants