Archivi tag: Python

Othello Board Game with Gymnasium compliant interface

The repository at https://github.com/pghedini/OthelloGymnasium contains an implementation of OTHELLO – often also called REVERSI – with OpenAI Gymnasium interfaces. The environment is for researchers and engineers who are interested in developing model-based Artificial Intelligence Reinforced Learning algorithms.

To use the package in Interactive mode, follow these steps:

import gymnasium
import othello_ai
env = gymnasium.make('othello_ai/Othello-v0', render_mode='ansi', board_size=6)
# if you choose 'human' render_mode, use env.render() to display board 
# start a new game
env.reset()
#
# env.render() # to eventually display board
#
# get the color next to move
next_move = lambda x: "BLACK" if x == -1 else "WHITE"
next_move(env.unwrapped.player_turn)
# get possible moves
env.unwrapped.get_possible_moves
# move
env.step(8)
# get the color next to move
next_move(env.unwrapped.player_turn)
# get possible moves
env.unwrapped.get_possible_moves
# move
env.step(7)
# move till the game end...
# ...
# close the env when finished
env.close()

Digging Twitter Users with Python

Digging Twitter Users with Python

Digging Twitter Users with Python

Tanks to the powerful Twitter REST API, it is easy with few lines of python code to extract useful information from the Twitter Engine.

The tool is written in python – it works in Python 2.7 and Python 3 – and it is quite handy to dig Twitter users, in particular it deals with Followers and Friends of a Twitter Account. You can download the code from https://github.com/pghedini/twitter_users

Features

The tool, by means of Twitter REST API, gets Followers and Friends of a given user. it provides the New followers and the Lost followers since the previous run.

It gives also the Not Following Friends: the Friends not following the given user.

Tot: 520 follower.
New follower: 10
Lost follower: 1
Unchanged follower: 509

Tot: 795 friends.
Friends not following: 355

In verbose mode, the tool gives the lists of New Followers, of Lost Followers and Not Following Friends.

Conclusion

The code is straightforward and you will be able to modify it to custom its features.

Enjoy and let me know if you like it in twitter @pierfghedini.

Pierfrancesco Ghedini

Licenza Creative Commons
Quest’opera è distribuita con Licenza Creative Commons Attribuzione 3.0 Italia.