Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change EvolvablePlayer serialization to write strings instead of bytes #1267

Merged
merged 2 commits into from
Oct 21, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions axelrod/evolvable_player.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base64
from pickle import dumps, loads
from random import randrange
from typing import Dict, List
Expand Down Expand Up @@ -36,12 +37,14 @@ def create_new(self, **kwargs):

def serialize_parameters(self):
"""Serialize parameters."""
return dumps(self.init_kwargs)
pickled = dumps(self.init_kwargs) # bytes
s = base64.b64encode(pickled).decode('utf8') # string
return s

@classmethod
def deserialize_parameters(cls, serialized):
"""Deserialize parameters to a Player instance."""
init_kwargs = loads(serialized)
init_kwargs = loads(base64.b64decode(serialized))
return cls(**init_kwargs)

# Optional methods for evolutionary algorithms and Moran processes.
Expand Down