IrishMike

IrishMike

Kotlin and Android Development featuring Jetpack: Treating method as a Property (Page 111)

Page 111 has:
fun playAITurn(
players: List,
currentPlayer: Player,
slots: List,
canPass: Boolean = false
): TurnResult? =
currentPlayer.selectedAI?.let { ai →
if (!canPass || ai.rollAgain(slots)) {
roll(players, currentPlayer, slots)
} else {
pass(players, currentPlayer)
}
}

Yet selectedAI() is defined in data class NewPlayer as follows:

fun selectedAI() = if (!isHuman.get()) {
    AI.basicAI.getOrNull(selectedAIPosition)
} else {
    null
}

Question: How can selectedAI() function be called using just selectedAI ??

Thank you
Mike (fairly new to Kotlin with little knowledge of Java)

Marked As Solved

mfazio23

mfazio23

Author of Kotlin and Android Development featuring Jetpack

Hey Mike!
You’re correct that selectedAI() in NewPlayer is a function, but it’s a property inside Player, which is the class referenced in the playAITurn() function.

NewPlayer calculates the AI, Player takes that value to be used later.

Hope this helps!

Where Next?

Popular Pragmatic Bookshelf topics Top

New
jon
Some minor things in the paper edition that says “3 2020” on the title page verso, not mentioned in the book’s errata online: p. 186 But...
New
GilWright
Working through the steps (checking that the Info,plist matches exactly), run the demo game and what appears is grey but does not fill th...
New
ianwillie
Hello Brian, I have some problems with running the code in your book. I like the style of the book very much and I have learnt a lot as...
New
rmurray10127
Title: Intuitive Python: docker run… denied error (page 2) Attempted to run the docker command in both CLI and Powershell PS C:\Users\r...
New
jskubick
I’m running Android Studio “Arctic Fox” 2020.3.1 Patch 2, and I’m embarrassed to admit that I only made it to page 8 before running into ...
New
jskubick
I think I might have found a problem involving SwitchCompat, thumbTint, and trackTint. As entered, the SwitchCompat changes color to hol...
New
AufHe
I’m a newbie to Rails 7 and have hit an issue with the bin/Dev script mentioned on pages 112-113. Iteration A1 - Seeing the list of prod...
New
taguniversalmachine
Hi, I am getting an error I cannot figure out on my test. I have what I think is the exact code from the book, other than I changed “us...
New
redconfetti
Docker-Machine became part of the Docker Toolbox, which was deprecated in 2020, long after Docker Desktop supported Docker Engine nativel...
New

Other popular topics Top

AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
AstonJ
If it’s a mechanical keyboard, which switches do you have? Would you recommend it? Why? What will your next keyboard be? Pics always w...
New
malloryerik
Any thoughts on Svelte? Svelte is a radical new approach to building user interfaces. Whereas traditional frameworks like React and Vue...
New
axelson
I’ve been really enjoying obsidian.md: It is very snappy (even though it is based on Electron). I love that it is all local by defaul...
New
AstonJ
Or looking forward to? :nerd_face:
New
Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
DevotionGeo
I know that -t flag is used along with -i flag for getting an interactive shell. But I cannot digest what the man page for docker run com...
New
mafinar
Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
New
rustkas
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New
PragmaticBookshelf
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
New

Sub Categories: