
commonMain.ro.sevens.ai.communication.LocalCommunication.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ai-jvm Show documentation
Show all versions of ai-jvm Show documentation
AI classes used in sevens
package ro.dragossusi.sevens.ai.communication
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import ro.dragossusi.sevens.ai.player.LocalPlayerListener
import ro.dragossusi.sevens.ai.room.AiRoom
import ro.dragossusi.sevens.game.bridge.AbsCommunication
import ro.dragossusi.sevens.game.listener.PlayerListener
import ro.dragossusi.sevens.game.room.Room
import ro.dragossusi.sevens.game.round.Round
import ro.dragossusi.sevens.game.session.PlayerSession
import ro.dragossusi.sevens.payload.Card
import ro.dragossusi.sevens.payload.Player
import kotlin.coroutines.CoroutineContext
/**
* sevens-client
*
* Copyright (C) 2020 Rachieru Dragos-Mihai
*
* sevens-client is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* sevens-client is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with sevens-client. If not, see [License](http://www.gnu.org/licenses/) .
*
*/
abstract class LocalCommunication> constructor(
protected val aiRoom: AiRoom,
player: Player,
dispatcher: CoroutineDispatcher,
protected val playerListener: L
) : AbsCommunication(), CoroutineScope {
protected val playerSession = PlayerSession(aiRoom.room, player)
override val coroutineContext: CoroutineContext = dispatcher + Job()
override fun placeCard(card: Card) {
launch {
aiRoom.room.addCard(playerSession, card)
}
}
override fun connect() {
launch {
aiRoom.addPlayer(playerSession, playerListener)
for (i in 1 until aiRoom.type.maxPlayers)
aiRoom.addAi("AI $i")
}
}
override fun disconnect() {
launch {
aiRoom.room.stop()
}
}
override fun drawCard() {
TODO("Not yet implemented")
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy